Standard Bookmarks not detected

G

Greg Mc

Many users (approx 1500+) in my company use a macro that
is stored in their Normal.Dot to fax standard letters to
customers using our desktop faxing program. The macro was
written by someone who has since left the company and was
initially distributed over 4 years ago and has worked
without a hitch.

It was written for Word '97 and the vast majority of users
still use this version.

These standard letters are automatically created using a
basic company fax header from 2 other applications without
any complications. In this standard template are bookmarks
so that data can be placed in the correct location.

When the faxes are created from application 2, there are
instances where the user will amend some of the text where
the bookmarks are (eg the fax no, to name etc). If they
then execute the macro the error "1005 - This Bookmark
Does not Exist" occurs. here is the code sample:

WordBasic.WW7_EditGoTo "ToFacsimile"
WordBasic.EndOfLine 1
WordBasic.Charleft 1, 1
fa = WordBasic.[Selection$]() 'Fax Number

If I go to Insert Bookmarks, the bookmarks appear in the
List or if I run this code from Knowledge Base article
163810 each bookmark is displayed
Sub GetBookMarksByName()
Dim bmBookMark As Bookmark
For Each bmBookMark In ActiveDocument.Bookmarks
MsgBox bmBookMark.Name
Next
End Sub

Why does this error occur even though the bookmark is
there and is there a way to get around this.
 
J

Jezebel

The problem may be that the bookmark is a property of the document range, so
if you select a bookmark and insert some text, the range is replaced and the
bookmark is deleted -- hence the code fails if you then amend the text and
try to re-insert.

Two ways to fix it:

1) Use DocProperties rather than bookmarks; or

2) Using the existing method, after the text is inserted, redefine the
bookmark.
 

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