Excel VBA Objects- VBA

Excel VBA Objects

An object is a thing which contains data and has properties and methods. Properties are the characteristics or attributes that describe the object, a Method is an action performed by an object. While writing vba code in Microsoft Office Excel, you will be using the objects provided by the Excel object model.

VBA Objects

An object is a thing which contains data and has properties and methods. Properties are the characteristics or attributes that describe the object (like name, color, size) or define an object's behavior. An object's data or information can be accessed with properties. A Method is an action performed by an object. Calling a Method will execute a vba code which will cause the object to perform an action. 

When programming using VBA, there are few important objects that a user would be dealing with.
  • Application Objects
  • Workbook Objects
  • Worksheet Objects
  • Range Objects


Application Objects 

The parent of all objects is Excel itself. We call it the Application object. The application object gives access to a lot of Excel related options. which can be called only when we use the application object such as calling the excel function in VBA code

Dim i As Integer

Application.ScreenUpdating = False

For i = 1 To 10000
Range("A1").Value = i
Next i

Application.ScreenUpdating = True


we are using the application object to disable the screen updating during the execution of our code

Workbook Objects

We call it the Workbook Objects. The application object gives access to a lot of Excel related options. which is mostly used when we are working with any workbook object such as opening new workbook and working with current workbook through VBA code

Workbooks.Add
Thisworkbook.worksheet1.select


Worksheet Objects

We call it the Worksheet Objects. The application object gives access to a lot of Excel related options. which is mostly used when we are working with any worksheet object such as adding worksheet and working with active worksheet through VBA code

Worksheets("Sales").Range("A1").Value = "Hello"
Sheet1.Range("A1").Value = "Hello"


Range Objects

We call it the Range Objects . The application object gives access to a lot of Excel related options. which is mostly used when we are working with any range object such as selecting range through VBA code

Range("A1").Value = "Hello"
Range("A1").select

Post a Comment

0 Comments