Data Type - Object
This data type contains a reference (or an address) to an actual object.
This can be used to contain any type of object (or Reference Type).
This data type uses 4 bytes.
The default value is Nothing.
Dim myObject As Object
Avoid This Data Type
Using the generic Object data type is much less efficient than using the specific object declaration.
Whenever you use this data type it will always use late binding.
You can find out if an Object variable has been set by using the "Is Nothing" keywords.
It makes your code less readable.
The reasons for this is because Excel cannot tell what type of object the variable refers to until the program is running, which obviously consumes some execution time.
This is referred to as late binding and can make programs run significantly more slowly.
Late Binding
Using the Object data type will declare the variable using late binding.
Dim oWorkbook As Object
Early Binding
Dim oWorkbook As Workbook
Set Keyword
You cannot assign an object to a variable using an equals sign.
Instead you must always use the "Set" statement.
GetObject Function
GetObject - Returns the reference to an object provided by an ActiveX component.
This can be used when you want to access a current instance of an object.
This code adds a new workbook to the current Excel instance.
Dim oXLApp As Excel.Application
Dim oWbk As Excel.Workbook
Set oXLApp = GetObject(ThisWorkbook.Name).Application
Set oWbk = oXLApp.Workbooks.Add
CreateObject Function
CreateObject - Returns the reference after creating a new ActiveX or OLE Object.
This code can be usedfrom Word to create an instance of Excel using early binding.
Dim oXLApp As Excel.Application
Dim oWbk As Excel.Workbook
Set oXLApp = CreateObject("Excel.Application")
Set oWbk = oXLApp.Workbooks.Add
© 2025 Better Solutions Limited. All Rights Reserved. © 2025 Better Solutions Limited TopPrevNext