Show the current environment in Excel

It is important to know the Excel environment before starting a VBA macro. It is important for a VBA macro to set macro variables with key indicators to define the current environment to enable restoring the current environment before completion. Since many Excel VBA operations are executed on the current/active environment, changing the environment to execute can be necessary. Restoring the original environment in a necessary function of a VBA macro. In addition the time to manually restore the environment there is a possiblity that full restoration will not occur.

SAS Fifth Dimension Macro-Current environment

The current directory, active workbook name, active worksheet name, current row number, and current column number are some of the basic elements. The number of opened workbooks and their names, the number of sheets in each workbook and their names, the number of shapes and their types, the number of hyperlinks and their locations are a few more.

Knowing the format of a cell can be critical during assignment. Comparing two cells can be affected by the format of the cells. So being able to check the format of a cell is necessary.

Review the following code, copy it to Excel and execute it.

    BOOK_NAME = ActiveWorkbook.Name
    SHEET_COUNT = Worksheets.Count
    SHEET_NAME = ActiveSheet.Name
    CURROW = ActiveCell.Row
    CURCOL = ActiveCell.Column
    CELL_FONT_NAME = ActiveCell.Font.Name
    CELL_FONT_SIZE = ActiveCell.Font.Size
    CELL_HIGHT = ActiveCell.RowHeight
    CELL_WIDTH = ActiveCell.ColumnWidth
    CELL_FORMAT = ActiveCell.Cells.NumberFormat
    CELL_ADDRESS = ActiveCell.Address