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?
Doug Robbins - Word MVP - 06 Jan 2007 18:50 GMT
See the article "Inserting text at a bookmark without deleting the bookmark"
at:
http://www.word.mvps.org/FAQs/MacrosVBA/InsertingTextAtBookmark.htm

Signature
Hope this helps.
Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.
Doug Robbins - Word MVP
>I am trying to have Word 2000 (controlled by Access 2000) replace the
>contents of named enclosing bookmarks. I want to preserve the original
[quoted text clipped - 20 lines]
>
> What am I doing wrong?
Jezebel - 06 Jan 2007 21:56 GMT
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.
>I am trying to have Word 2000 (controlled by Access 2000) replace the
>contents of named enclosing bookmarks. I want to preserve the original
[quoted text clipped - 20 lines]
>
> What am I doing wrong?