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 / July 2007

Tip: Looking for answers? Try searching our database.

Bookmarks

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Neal - 02 Jul 2007 16:04 GMT
Does anyone know how to create a macro that would insert a bookmark from
another document that may not be active to an active document?  Would love to
get an idea of the code.
Bear - 02 Jul 2007 17:10 GMT
Neal:

If you know the filename and the bookmark name, the statement to insert the
content of that bookmark becomes:

Selection.InsertFile FileName:="Doc1.doc", Range:="BearTest", _
       ConfirmConversions:=False, Link:=False, Attachment:=False

The VBA Help explains the use of all the properties shown. The Range is the
bookmark name.

Bear
Signature

Windows XP, Word 2000

> Does anyone know how to create a macro that would insert a bookmark from
> another document that may not be active to an active document?  Would love to
> get an idea of the code.
Jay Freedman - 02 Jul 2007 17:14 GMT
> Does anyone know how to create a macro that would insert a bookmark
> from another document that may not be active to an active document?
> Would love to get an idea of the code.

Use an INCLUDETEXT field, and place the name of the bookmark after the name
of the file -- look of the field's syntax in the Word Help.

To do this in a macro, use the ActiveDocument.Fields.Add method like this
(notice that the file name must be in quotes if it contains spaces, and all
backslashes must be doubled):

Sub demo()
   Dim Fname As String, BKname As String
   Fname = "C:\somepath\source.doc"
   Fname = Chr(34) & Replace(Fname, "\", "\\") & Chr(34)
   BKname = "somebookmark"

   With ActiveDocument.Fields
       .Add Range:=Selection.Range, _
         Type:=wdFieldIncludeText, _
         Text:=Fname & " " & BKname, _
         PreserveFormatting:=True
       .Update
   End With
End Sub

Signature

Regards,
Jay Freedman
Microsoft Word MVP        FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.

 
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.