Bookmark Programming

  • Thread starter Microsoft Newsgroups
  • Start date
M

Microsoft Newsgroups

I am trying to have Word 2000 (controlled by Access 2000) replace the
contents of named enclosing bookmarks. I want to preserve the original name
as well as the bookmark.

I understand that I cannot simply replace the text, but that I have to
locate the bookmark, delete it and replace it with another with the same
name. (It would, of course, simply be easier to replace the text!) This is
my procedure which keeps resulting in a "type mismatch" error when I go to
add the new bookmark:

Public Function DoBookmarks(BookmarkName As String, Optional ReplacementText
As String, Optional SaveTheBookmark As Boolean)
With ActiveDocument
If .Bookmarks.Exists(BookmarkName) = True Then
.Bookmarks(BookmarkName).Select
.Bookmarks(BookmarkName).Delete
If ReplacementText <> "" Then
.Bookmarks.Add Name:=BookmarkName, Range:=ReplacementText
End If
End If
End With
End Function

What am I doing wrong?
 
J

Jezebel

The fault is this line:

.Bookmarks.Add Name:=BookmarkName, Range:=ReplacementText

The Range argument needs to be a range within the document.

A much simpler solution is to use document properties and DocProperty
fields. Then you don't have to do any of this. Just set the properties, then
update fields.
 

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