Please help! Error 5101 Bookmark does not Exist--but it does

A

Al

I am updating an MS Word document from MS Access, below is my code. The
following statement works when I have a reference to the VBA Microsoft Word
Object Library 10.0 in Access set, but I receive Error no: 5101 “This
bookmark does not existâ€.
when I uncheck the Microsoft Word Object Library 10.0 reference in Access
VBA: (reference ** in code)

appWord.Selection.Goto What:=wdGoToBookmark, Name:="IIIA1"

I wish to use late-binding in this application so it will work more
universally. What is wrong with this statement?

Also, will the next 2 statements work without modification?

Is there a source for MS Word error no. descriptions? Also, where can I
read more about Word objects—what they are and how to use them?

Thanks for your assistance!!

Alan

ACCESS CODE FOLLOWS:

‘DECLARE VARS
Dim appWord As Object
Dim Docs As Object

‘OPEN MW WORD AND DOCUMENT
strSched = "C:\Templates\Document.dot
Set appWord = GetObject(, "Word.Application")
Set Docs = appWord.Documents
Docs.Add strSched

‘GOTO BOOKMARK AND HIDE TEXT
** appWord.Selection.Goto What:=wdGoToBookmark, Name:="IIIA1"
appWord.Selection.MoveRight Unit:=wdCharacter, Count:=198,
Extend:=wdExtend
appWord.Selection.Font.Hidden = True

‘QUITE MS WORD AND RESET DIM VARS
appWord.Quit
Set appWord = Nothing
Set Docs = Nothing
 
J

Jonathan West

Al said:
I am updating an MS Word document from MS Access, below is my code. The
following statement works when I have a reference to the VBA Microsoft
Word
Object Library 10.0 in Access set, but I receive Error no: 5101 “This
bookmark does not existâ€.
when I uncheck the Microsoft Word Object Library 10.0 reference in Access
VBA: (reference ** in code)

appWord.Selection.Goto What:=wdGoToBookmark, Name:="IIIA1"

I wish to use late-binding in this application so it will work more
universally. What is wrong with this statement?


When you use late binding, Word's constants are no longer known to the
application and you have to define them for yourself.

Include the following line in your routine

Const wdGoToBookmark = -1
Also, will the next 2 statements work without modification?

ACCESS CODE FOLLOWS:

‘DECLARE VARS
Dim appWord As Object
Dim Docs As Object

‘OPEN MW WORD AND DOCUMENT
strSched = "C:\Templates\Document.dot
Set appWord = GetObject(, "Word.Application")
Set Docs = appWord.Documents
Docs.Add strSched

‘GOTO BOOKMARK AND HIDE TEXT
** appWord.Selection.Goto What:=wdGoToBookmark, Name:="IIIA1"
appWord.Selection.MoveRight Unit:=wdCharacter, Count:=198,
Extend:=wdExtend
appWord.Selection.Font.Hidden = True

‘QUITE MS WORD AND RESET DIM VARS
appWord.Quit
Set appWord = Nothing
Set Docs = Nothing

Similarly, with late binding the Word constants wdCharacter and wdExtend are
not predefined. They need to be explicitly defined as follows

Const wdCharacter = 1
Const wdExtend = 1
Is there a source for MS Word error no. descriptions?

In the Word VBA Help file there is a topic titled Trappable Errors. If you
loo up the Error function in the VBA help, it is one of the pages listed in
the "See Also" link.
Also, where can I
read more about Word objects—what they are and how to use them?

The Word VBA Help file is the place. A very good initial overview can also
be found here

Getting To Grips With VBA Basics In 15 Minutes
http://word.mvps.org/FAQs/MacrosVBA/VBABasicsIn15Mins.htm
 
H

Helmut Weber

Hi Al,

I'd say, if you use late binding,
access doesn't know word constants like wdGoToBookmark.
Same applies to wdCharacter.
You may use the corresponding values instead.
wdGoToBookmark= -1
wdCharacter= 1

Greetings from Bavaria, Germany
Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word XP, Win 98
http://word.mvps.org/
 
A

Al

Thanks Jonathan (&Helmut)

Setting those parameters worked.

So now my question is how did you know what to set the parameters to? Is
there documentation somewhere with the available settings for what: (-1 for
bookmark), Unit: (1 for character), Extend:(1 for ?)
 
J

Jonathan West

Al said:
Thanks Jonathan (&Helmut)

Setting those parameters worked.

So now my question is how did you know what to set the parameters to? Is
there documentation somewhere with the available settings for what: (-1
for
bookmark), Unit: (1 for character), Extend:(1 for ?)

Hi Al,

When working with early binding or within VBA itself, you get prompted for
the constant names.

To get the values, open the VBA editor in the application, or alternatively
temporarily set an early binding reference again, and then just get the
value of the constant to print out in the immediate window.
 

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