A simple example of late binding

The following example demonstrates how to create a Word object by using late binding. This procedure creates the object, displays the version number, closes the Word application, and then destroys the object (thus freeing the memory that it used).

Sub GetWordVersion()

Dim WordApp As Object

Set WordApp = CreateObject("Word.Application") MsgBox WordApp.Version WordApp.Quit Set WordApp = Nothing End Sub

The Word object that's created in this procedure is invisible. If you'd like to see the object while it's being manipulated, set its Visible property to True,as follows:

WordApp.Visible = True

This example can also be programmed using early binding. Before doing so, choose the Tools ^ References command to set a reference to the Word object library. Then you can use the following code:

Sub GetWordVersion()

Dim WordApp As New Word.Application MsgBox WordApp.Version WordApp.Quit Set WordApp = Nothing End Sub

0 0

Post a comment