Question re late-binding in Office

V

VanS

Greetings,
I have an Excel/Word VBA app with automation and I need to make it backward
compatible to Office 97. I am considering late-binding as the simplest
solution despite reduced efficiency, but wanted to confirm I understand the
process. I have read several KB articles and just want to confirm: this issue
is pertinent only when declaring an object, correct? IE I have no variable
declaration as
Dim excl as excel.object
but only Public wrd as word.application. So I would simply need to
re-declare that as: Public wrd as Object
Correct? There are no other elements regarding late binding?
Thanks, God bless
Van
 
P

Peter

To use late binding, you declare the application objects as type Object, then use the CreateObject statement to "bind" them to a particular application object. Also, constants are no longer available.

For example, to find the folder in which Word is installed, you create an instance of the Word application and query it for its program path:

Const wdProgramPath as Integer = 9
Dim oWd as Object
Dim oFldr as String

Set oWd = CreateObject("Word.Application")
oFldr = oWd.Options.DefaultFilePath(wdProgramPath)
Call oWd.Quit(False)
Set oWd = Nothing

Notice that I had to declare the constant wdProgramPath. It would have been defined had I added a reference to the Word Object Library in my project and used early binding, but since I didn't, I had to make sure the constant was defined. 'Course, I could've just used the number 9, but I like the readability of defining constants.

One thing I often do is use early binding while developing a project in order to take advantage of IntelliSense and help files, then change to late binding when I'm ready to distribute to take advantage of version independence and more friendly error handling. Unless, of course, the project requires a particlular version of an object.

hth,

-Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top