Microsoft Office Tutorials and References
In Depth Information
Late Binding
In late binding , the matching process between the object variable and the object takes place
when the application is run. The result is slower performance compared to early binding , in
which the binding takes place when the application is compiled.
With late binding, you need to declare general object variables because the Object Library
belonging to the foreign application is not activated. It is more challenging to program the
foreign objects because the properties, methods, and events won’t automatically appear while
programming your procedure in regard to the foreign object. However, late binding lets you
create an Application object regardless of the version installed on the user’s system. This is the
preferred method of binding when the file will be distributed to users that might have differ
ent versions of the software. Therefore, your procedure would open Microsoft Word
regardless of the version installed.
You use the CreateObject function to create the object or the GetObject function to create the
instance of the application. The object is then declared as a generic Object type, and its object
reference is resolved at run time. The following procedure displays how to use late binding
with the Word application:
Sub UsingLateBinding()
Dim oApp As Object
Dim oDoc As Object
On Error Resume Next
Set oApp = GetObject(, "Word.Application”)
If oApp Is Nothing Then
Set oApp = CreateObject("Word.Application”)
End If
On Error GoTo 0
If oApp Is Nothing Then
MsgBox "The application is not available!", vbExclamation
End If
With oApp
.Visible = True
Set oDoc = _
.Documents.Open("C:\GSC\Employee Info\Health Benefits.doc”)
oDoc.Close True
.Quit
End With
Set oDoc = Nothing
Set oApp = Nothing
End Sub
This additional sample procedure also uses late binding but shows you how to create an entry
in the Outlook Calendar.
Search JabSto ::




Custom Search