Re: Question re late-binding in Office

From: Peter (peterguy)
Date: 12/13/04


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



Relevant Pages

  • Re: how to declare a fileSystemObject?
    ... Dim fs As Scripting.FileSystemObject ... with early binding. ... In answer to the original post, declare fs and a as Objects: ... Dim intFile As Integer ...
    (microsoft.public.access.macros)
  • Re: Querying a database
    ... Use My Database ... Declare @sCnt VarChar ... Set Nocount Off ... Dim pairsAdapter As New MWFNTableAdapters.MWFNTableAdapter ...
    (microsoft.public.vb.database)
  • Re: tab in userform locks program
    ... > I am a VBA newbie and have not been using DIM in my code so it is ... declare a variable at the top of a standard module using Private (module ... You may notice that I used Format$ instead of Format. ... but Format$ returns a String whereas ...
    (microsoft.public.excel.programming)
  • RE: Declarations Procedure and Duplicate Declarations
    ... I commented out the dim statement and the damn thing compiled. ... Sub Want_Info ... Otherwise within the procedure when you make reference to hserow are you ... I am getting a dupe declare compile error on hserow in the following: ...
    (microsoft.public.excel.programming)
  • Re: Tasks and Calendar
    ... ' Declare the variable. ... Dim oAppt as Outlook.AppointmentItem ... >> function returns an Items collection which you can loop through. ... >> For Each AnyObj in AnyCollection ...
    (microsoft.public.outlook.program_vba)