Early Binding vs Late Binding

Published on September 10, 2010

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


Tags:
Like this article? Share it!

Leave a Comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

Privacy Policy