I know I'm getting into this late but could this code be modified to create a
cross reference based on existing bookmarks in the document. The situation
is this....I have multiple headers in a document due to portrait and
landscape pages. There are 4 bookmarks in the header (DOC_NAME, DOC_VERSION,
DOC_TITLE, DOC_SITE). The headers each need the same bookmarks. I have a
macro to add the bookmarks but the bookmarks are only retained in the last
header. I'm wondering if I can search the headers where the bookmark was
lost and include cross reference code. For example, search for "[DOC_NAME]
and have code that cross references it to the bookmark DOC_NAME.
Any help is very much appreciated.
Thanks,
Mickey
Russ said:
Kurtis,
You could try:
Dim n as Long
Dim myBookmark as String
n = ActiveDocument.Bookmarks.Count + 1
myBookmark = "b" & Cstr(n)
Then replace "b" in your code below with the variable myBookmark, verbatim
(without quotation marks), in both places.
Here is the new code:
With ActiveDocument.Bookmarks
.Add Range:=Selection.Range, Name:="b"
.DefaultSorting = wdSortByLocation
.ShowHidden = True
End With
Selection.InsertCrossReference ReferenceType:="Bookmark",
ReferenceKind:= _
wdNumberFullContext, ReferenceItem:="b", InsertAsHyperlink:=True, _
IncludePosition:=False
End Sub
Is there a way to generate a new bookmark Name (in this case "b") and copy
it to the ReferenceItem (b) each time the macro is run?
:
Thanks for your response. That makes sense, but how do I automate the
process? How can I make it reflect the correct paragraph context each time
the macro is run?
:
Hi Kurtis,
The ReferenceItem will be a bookmark - either one you've created or one
that
Word has created and for which you know the ID/Name.
Cheers
--
macropod
[MVP - Microsoft Word]
I am having a problem with a cross reference and would really appreciate
some
help. What I am trying to do is create a macro that will insert a full
context cross reference that references the current paragraph. For
instance,
par. 3.5 states "except as provided on Schedule 3.5. Here is my code so
far:
Selection.InsertCrossReference ReferenceType:="Numbered item", _
ReferenceKind:=wdNumberFullContext, ReferenceItem:="?",
InsertAsHyperlink _
:=True, IncludePosition:=False
End Sub
Any help on this would be greatly appreciated.