Early Binding vs Late Binding

When connecting a macro with an external application, like Microsoft Excel, an object variable must be “bound” to an instance of the application’s object. In early binding a reference is to the external application using Tools > References from the VBA pull-down menu, and then declaring an object variable to the referenced application object. In Late binding no reference is made and the application variable is declared as a generic object type. Early binding is the preferred method as it allows you to use VBA’s Intellisense feature during development and improves the performance of the application. Late binding is useful when checking to determine if the external application is installed.


'
' Requires Reference to Microsoft Excel Object Library
'
Sub EarlyBinding()
Dim objExcel As Excel.Application

Set objExcel = New Excel.Application

'
' Interact with Excel here
'

objExcel.Quit
Set objExcel = Nothing
End Sub

Sub LateBinding()
Dim objExcel As Object

Set objExcel = CreateObject("Excel.Application")

'
' Interact with Excel here
'

objExcel.Quit
Set objExcel = Nothing
End Sub

EnvisionCAD

Since 1996, EnvisionCAD has been a nationally recognized leader in the configuration, customization, implementation, training & support for CAD software solutions. Our individualized approach has benefited private engineering firms and government agencies alike. Basic or advanced, we can help you get the most from your CAD technology.

Tags:

Leave a Reply

Your email address will not be published. Required fields are marked *