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

by QWw » Tue, 04 Jan 2005 00:01:03 GMT

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 his
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 objectshat they are and how to use them?

Thanks for your assistance!!

Alan

ACCESS CODE FOLLOWS:

ECLARE VARS
Dim appWord As Object
Dim Docs As Object

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

OTO 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

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



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

by Jonathan West » Tue, 04 Jan 2005 00:13:14 GMT








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: >> >> ECLARE VARS >> Dim appWord As Object >> Dim Docs As Object >> >> PEN MW WORD AND DOCUMENT >> strSched = "C:\Templates\Document.dot >> Set appWord = GetObject(, "Word.Application") >> Set Docs = appWord.Documents >> Docs.Add strSched >> >> OTO 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 >> >> UITE 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 objectshat 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

--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup




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

by Helmut Weber » Tue, 04 Jan 2005 00:29:19 GMT

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/


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

by QWw » Tue, 04 Jan 2005 04:47:03 GMT

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 ?)











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

by Jonathan West » Tue, 04 Jan 2005 06:33:16 GMT





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.


--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup



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

by QWw » Tue, 04 Jan 2005 11:37:03 GMT

Thanks,

That worked. Now I know what the values are and how to see what they are.









Similar Threads

1. Runtime error 5101: This bookmark does not exist

I have created a merge template with a number of bookmarks in it.  However, 
on merging, the bookmarks disappear.  When I go to the bookmark list, none of 
the bookmarks are listed.  Without the bookmarks, a number of macros in the 
template don't work.  What am I doing wrong.  Thanks in advance.

2. Please help me why this script is not doing correctly

3. Error 5101 Bookmark Does Not Exist - Word VB Template - Help!!

Hello, [please let me know if this is wrong group]
I have searched for the problem that I am having and I have found 
similar references, but the fixes are correcting the minor issue that I 
am having.

Problem:  Getting Error 5101 after hitting "OK" on user input form.
Form Description:  It's a basic fax UserForm (Name, Pages, Destination, 
Fax No, Company, etc) that passes the characters from the UserForm onto 
designated positions in the Word document.

In my first creation of this template, everything works fine after 
filling out the form.  The text and #'s are passed onto the document 
perfectly.  However, I found that I started getting Error 5101 when I 
copied the code from my original project/templated for the creation of 
my second project/template which is almost identical but with a differnt 
caption for the UserForm .  I am also noticing that the UserForm for the 
second document (ProjectTemplate as it refers in VB pane) is referencing 
the UserForm from my orignial template.  I can tell this b/c each 
UserForm has a different caption.

Let me know if you have any ideas or suggestions: (Below is pasted code)



Private Sub PB_Cancel_Click()
     On Error GoTo PB_Cancel_Click_Error
     Application.ScreenUpdating = False
     Selection.GoTo What:=wdGoToBookmark, Name:="DocumentStart"
     Application.ScreenUpdating = True
     Unload Frm_Dialog
     Exit Sub
PB_Cancel_Click_Error:
     MsgBox "Error Number " & Err.Number & Chr$(13) & Chr$(10) & 
Err.Description, vbOKOnly + vbCritical, 
ActiveDocument.BuiltInDocumentProperties("Company") & " " & 
ActiveDocument.BuiltInDocumentProperties("Title")
     Application.ScreenUpdating = True
     Unload Frm_Dialog
End Sub

Private Sub PB_OK_Click()
     On Error GoTo PB_OK_Click_Error
     Application.ScreenUpdating = False
     'Insert To Field.
     Selection.GoTo What:=wdGoToBookmark, Name:="DocumentStart"
     Selection.InsertBefore Text:=TB_To.Text
     'Insert Destination.
     Selection.GoTo What:=wdGoToBookmark, Name:="Destination"
     Selection.InsertBefore Text:=TB_Destination.Text
     'Insert Company.
     Selection.GoTo What:=wdGoToBookmark, Name:="Company"
     Selection.InsertBefore Text:=TB_Company.Text
     'Insert Pages.
     Selection.GoTo What:=wdGoToBookmark, Name:="Pages"
     Selection.InsertBefore Text:=TB_Pages.Text
     'Insert From Field.
     Selection.GoTo What:=wdGoToBookmark, Name:="From"
     Selection.InsertBefore Text:=TB_From.Text
     'Insert Sender Field.
     Selection.GoTo What:=wdGoToBookmark, Name:="Sender"
     Selection.InsertBefore Text:=TB_Sender.Text
     'Insert Date.
     Selection.GoTo What:=wdGoToBookmark, Name:="Date"
     Selection.InsertBefore Text:=TB_Date.Text
     'Insert Subject.
     Selection.GoTo What:=wdGoToBookmark, Name:="Subject"
     Selection.InsertBefore Text:=TB_Subject.Text
     '*Position insertion point for user.
     Selection.GoTo What:=wdGoToBookmark, Name:="DocumentEnd"
     Application.ScreenUpdating = True
     Unload Frm_Dialog
     Exit Sub
PB_OK_Click_Error:
     MsgBox "Error Number " & Err.Number & Chr$(13) & Chr$(10) & 
Err.Description, vbOKOnly + vbCritical, 
ActiveDocument.BuiltInDocumentProperties("Company") & " " & 
ActiveDocument.BuiltInDocumentProperties("Title")
     Application.ScreenUpdating = True
     Unload Frm_Dialog
End Sub


Private Sub UserForm_Activate()
     Frm_Dialog.Caption = 
ActiveDocument.BuiltInDocumentProperties("Company") & " - " & 
ActiveDocument.BuiltInDocumentProperties("Title")
     TB_From = Application.UserName
     TB_Date = Format(Date, "MMMM dd, yyyy")
End Sub

4. Please help i need to get homework done - Word Document management

5. Help With Time Formats When Doing A Mail Merge PLEASE

Anyone who can help me I would appreciate it!
If I have an excel file or access database file that I am using as a
data source when doing a mail merge, how come the time format changes
in them? Example: I have a column of appointment times in the short
time format (5:00 PM) for example. It appears this way in both access
and excel. But when I merge that field into a documnet using Word mail
merge, the field ends up displaying as 5:00:00 PM - the "seconds"
indicator gets added in. Does anyone know how to fix this???
Thank you.

6. I think Im doing it all wrong - Please Help - VB.Net

7. Strange Problem doing DOS Dir Command in VBA Help Please

Hi Everyone.

This problem is driving me crazy.

Im using Access2003.

Basically what I wish to do is create a new record for each jpg bmp or gif
file in the current directory.

I need to just save the path and filename of each file in a table in its own
record

I am trying to do a DOS command to do a DIR of jpg, bmp and gif files, and
save the output to a file C:\Filelist.txt
using the following line.

        Shell (Environ$("COMSPEC") & " /c  Dir *.jpg *.bmp *.gif /S /B >
C:\Filelist.txt")

I then try to read that file into the Imagepath field with VBA doing the
following:

    Dim Q as string

    Open "C:\Filelist.txt" For Input As #1

     While Not EOF(1)

           DoCmd.GoToRecord , , acNewRec
           Line Input #1, Q
           Imagepath = Q


     Wend

    Close#1



Works OK first time used, creates a set of new records, one for each jpg bmp
and gif file in the directory. Bewdy.

But on second and subsequent uses (and a change of the current directory) it
creates a duplicate of the previously created set of records instead of the
contents of C:\Filelist.txt (ie Pass1 creates records OK, Pass2 creates same
records as Pass1, Pass3 creates same records as pass2 etc)

I checked C:\Filelist.txt and it has been created successfully each time

Yet VBA reads its contents incorrectly. Seems to ignore the fact that
C:\Filelist.txt has been overwritten.Always seems to
be one pass behind.

I have even tried using a macro to import C:\Filelist.txt as a table and do
an append query but same problem.

The behaviour of C:\Filelist.txt is odd.


Any help would be extremely appreciated.


Thank you.

Joe.



8. HELP!! Christmas labels done in table not printing - MS Word