Early vs Late Binding - Word

J

John Wilson

I'm finally getting a taste (quite sour) of Office 2003.
It came with the two new PC's so I didn't have much of a choice.
In many (actually all) of the workbooks where I interact with Word,
I used Early Binding. Since the initial workbooks were created in
Office 2000, when someone with a later version saves the workbook
the Word Object reference is set to version 11.
I've already read through many of the threads by Chip, Rob, etc.
and it's beginning to sink in (but a lot slower than I would have
hoped).

Whilst still getting a handle on this, I would appreciate it if someone
could convert the following code to utilize Late Binding.
I can get some of it to work, but not all. Any help would be
appreciated.

Dim wordApp As Word.Application
Dim wordDoc As Word.Document
Dim wordRange As Word.Range
Dim FileNameAndPath As String
FileNameAndPath = ActiveWorkbook.path & "\Forms\Fax_Cover_Master.doc"
Set wordApp = CreateObject("Word.Application")
Set wordDoc = wordApp.Documents.Open(FileNameAndPath, ReadOnly:=True)

Thanks,
John
 
C

Chip Pearson

John,

Just change all the declarations for Word objects from "As Word.whatever" to
"As Object".


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
 
J

John Wilson

Chip,

Thanks for that.
I guess I was trying to overcomplicate things.
Anyway, your suggestion worked perfectly and many thanks.

I have one more associated dilemma, though.
Using your suggestion, the correct word document does open.
This line of code crashes though (it worked with early binding)

Set wordRange = wordDoc.Goto(What:=wdGoToBookmark, Name:="FaxTo")
The error that I get is that "This bookmark does not exist", but it does indeed
exist.

For reference, the coding per your suggestion that did work is as follows:
Dim wordApp As Object
Dim wordDoc As Object
Dim wordRange As Object
Dim FileNameAndPath As String
FileNameAndPath = ActiveWorkbook.path & "\Forms\Fax_Cover_Master.doc"
Set wordApp = CreateObject("Word.Application")
Set wordDoc = wordApp.Documents.Open(FileNameAndPath, ReadOnly:=True)

Again...many thanks,
John
 
J

John Wilson

Ron,

Thanks for that.
I did read it.
There are actually some very detailed threads in Google on the subject
and I've perused many of them too.
I don't usually ask "homework" type questions, but I was in a bind
(an early bind), since I have multiple users sharing files with
different versions of Office and I've been running around setting
and resetting object references all day.
I have everything running okay now on the old version PC's and the new
ones are off limits (under pain of death) until I can get this resolved.

Thanks,
John
 
J

Jake Marx

Hi John,

Since you're using Late Binding now, you must be sure to replace all named
constants with their actual values. VBA has no idea what wdGoToBookmark is,
so you should use -1 instead. You can get the value by going into Word,
opening the VBE, and typing ?wdGoToBookmark in the immediate window.

BTW, you should use Option Explicit at the top of each module - that way,
you would be warned that wdGoToBookmark is undefined.

--
Regards,

Jake Marx
MS MVP - Excel
www.longhead.com

[please keep replies in the newsgroup - email address unmonitored]
 
J

John Wilson

Jake,

That did the trick!!!
Thanks for the help.
you should use Option Explicit at the top of each module
As a rule, I usually do. I had it commented out whilst working
on this problem.

Thanks again,
John

Jake said:
Hi John,

Since you're using Late Binding now, you must be sure to replace all named
constants with their actual values. VBA has no idea what wdGoToBookmark is,
so you should use -1 instead. You can get the value by going into Word,
opening the VBE, and typing ?wdGoToBookmark in the immediate window.

BTW, you should use Option Explicit at the top of each module - that way,
you would be warned that wdGoToBookmark is undefined.

--
Regards,

Jake Marx
MS MVP - Excel
www.longhead.com

[please keep replies in the newsgroup - email address unmonitored]

John said:
Chip,

Thanks for that.
I guess I was trying to overcomplicate things.
Anyway, your suggestion worked perfectly and many thanks.

I have one more associated dilemma, though.
Using your suggestion, the correct word document does open.
This line of code crashes though (it worked with early binding)

Set wordRange = wordDoc.Goto(What:=wdGoToBookmark, Name:="FaxTo")
The error that I get is that "This bookmark does not exist", but it
does indeed exist.

For reference, the coding per your suggestion that did work is as
follows: Dim wordApp As Object
Dim wordDoc As Object
Dim wordRange As Object
Dim FileNameAndPath As String
FileNameAndPath = ActiveWorkbook.path &
"\Forms\Fax_Cover_Master.doc" Set wordApp =
CreateObject("Word.Application") Set wordDoc =
wordApp.Documents.Open(FileNameAndPath, ReadOnly:=True)

Again...many thanks,
John
 

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