VBA Application Properties

In this article, we will learn the useful application properties. When we work in Excel, only one workbook remains active that time, in workbook only one worksheet remains active, and in worksheet only one cell remains active.

We are going to learn the same situation in this topic. Through message box, we can find out that right now which cell is active in which worksheet of which workbook.

Now, you will have a question in your mind that how we can do it. Before learning how you can get to know, we will have a look on the lists of other application: –

Property Object Returned
ActiveCell To return the range object which is representing active cell in the active window.
ActiveChart To return the chart object that represent the active chart
ActiveSheet To return the object which is represents the active sheet.
ActiveWindow To return a window object that represent the active window
ActiveWorkbook To return a workbook object that represent the active workbook
Selection To return the selected object in the active window
ThisWorkbook To returns the workbook in which code is running

How we will use ActiveCell?
Follow below given steps:-

  • Open the Excel File and select any cell in worksheet and write anything in the cell
  • Press Alt+F11 to open the VBE and write the below mentioned code:-

Sub Properties()
ActiveCell.ClearContents
End Sub

Image 1

  • To run the code, press F5, and the content will get clear from the selected cell.

How we will use ActiveSheet?

Sub Properties()
MsgBox ActiveSheet.Name
End Sub

image 2

  • To run the code, press F5, and the message box will display the Active sheet name.

image 3

How we will use ActiveWorkbook?

Sub Properties()
MsgBox Activeworkbook.Name
End Sub

image 4

  • To run the code, press F5, and the message box will display the Active workbook name

image 5

How we will use ActiveWindow?

Sub Properties()
ActiveWindow.RangeSelection.Value = 30
End Sub

image 6

  • To run the code, press F5, and the message box will display the Active workbook name
  • Selected range will get filled with the value 30

image 7

These are all VBA application properties that we use to write the macro.

Previous Chapter Next Chapter

Leave a Reply