Bookmarks

N

Neal

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.
 
B

Bear

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
 
J

Jay Freedman

Neal said:
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

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
 

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