Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / January 2007

Tip: Looking for answers? Try searching our database.

Bookmark Programming

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Microsoft Newsgroups - 06 Jan 2007 18:45 GMT
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?
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.