Re: Question re late-binding in Office
From: Peter (peterguy)
Date: 12/13/04
- Next message: Durga Lal Shrestha: "VBA help is not working properly"
- Previous message: BobAtVandy: "Re: can return .Value but not set it"
- In reply to: VanS: "Question re late-binding in Office"
- Next in thread: VanS: "Re: Question re late-binding in Office"
- Reply: VanS: "Re: Question re late-binding in Office"
- Messages sorted by: [ date ] [ thread ]
Date: Mon, 13 Dec 2004 15:46:51 -0800
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
"VanS" <VanS@discussions.microsoft.com> wrote in message news:EDEE3050-6F02-45BB-8E86-D3E7DC5C8F6B@microsoft.com...
> 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
- Next message: Durga Lal Shrestha: "VBA help is not working properly"
- Previous message: BobAtVandy: "Re: can return .Value but not set it"
- In reply to: VanS: "Question re late-binding in Office"
- Next in thread: VanS: "Re: Question re late-binding in Office"
- Reply: VanS: "Re: Question re late-binding in Office"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|
|