Jay, I have been using this macro for sometime now and have one
change but cannot get find the right commands.
When the macro is run, the list of bookmarks is displayed perfectly
but their coding is for a hyperlink (as per line
"ActiveDocument.Hyperlinks.Add _") how can this be changed to show
the cross-reference "Ref" instead.
For example the code for a bookmark looks like this:
{ HYPERLINK "DocName.doc" \l "bk001" }
but would like instead:
{ REF bk001 \h }
Many thanks again.
DeanH
:
Fantastic, Jay.
Does exactly as required and will save me so much time.
All the best
DeanH
:
Ah, OK.
As MVP Greg Maxey pointed out to me in an email, this is one
situation where it's easier to use the Selection instead of a Range
object. That way you don't have to keep collapsing after every
insertion. I think this is what you're looking for:
Sub BookmarkIndex()
Dim bk As Bookmark
With Selection
.TypeParagraph
.Style = ActiveDocument.Styles("Index Heading")
.TypeText "Bookmarks" & vbCr
.Style = ActiveDocument.Styles("Index 1")
For Each bk In ActiveDocument.Range.Bookmarks
ActiveDocument.Hyperlinks.Add _
Anchor:=.Range, _
Address:=ActiveDocument.Name, _
SubAddress:=bk.Name, _
TextToDisplay:=bk.Range.Text
.TypeParagraph
Next
End With
End Sub
DeanH wrote:
Jay, thanks for text replacement.
Sorry about the "ned" - podgy-finger-syndrome this morning.
To clarify: my second request is not for an Index so I don't want
the macro to jump to the END of the document, but to display where
the cursor happens to be.
As I want a list of the bookmarks, I wont need the page numbers and
leaders, etc.
But I would like the list still to be hyperlinked.
Sorry for the confusion.
Many thanks again.
DeanH
:
To show the text of the bookmark, replace the line
rg.Text = bk.Name & vbTab
with
rg.Text = bk.Range.Text & vbTab
I don't understand your request to "not jump to the ned [I guess
you meant 'end'] of the document but still be hyperlinked". Can
you clarify?
On Fri, 10 Jul 2009 00:07:01 -0700, DeanH
Hello Jay.
A nice little helpful macro, thanks.
I have a slightly different requirement and have tried to edit
this macro without success.
I am after this Index to show the Bookmark Text (as in Cross
reference, Insert reference to
not the Bookmark Name, possible?
Also, if this possible, how would the macro be to produce a list
of these Bookmark Names without the page numbers, leaders, etc.
and not jump to the ned of the document but still be hyperlinked?
Many thanks for your assistance.
DeanH
:
Jay Freedman wrote:
NJK wrote:
It will be useful to be able to create an index of all the
bookmark names with their page number and hyperlink to that
bookmark.
eg
[BookmarkName]....[pageNumber]
The use of this will be very helpfull when software
requirement specifiers can have a list of all the bookmarks
from another document instead of having both documents open.
This will cut down in a lot of mouse moving.
An index of bookmarks can be created with a reasonably simple
macro (see
http://www.gmayor.com/installing_macro.htm if
needed): [snip]
Sorry, the previous macro produced a plain-text index without
any hyperlinks (which is all you would get from an ordinary
index). This version hyperlinks the page numbers back to the
bookmarks:
Sub BookmarkIndex()
Dim bk As Bookmark
Dim rg As Range
Set rg = ActiveDocument.Range
With rg
.Collapse wdCollapseEnd
.InsertBefore vbCr
.Style = ActiveDocument.Styles("Index Heading")
.Text = "Bookmarks" & vbCr
.Collapse wdCollapseEnd
.Style = ActiveDocument.Styles("Index 1")
.ParagraphFormat.TabStops.Add _
Position:=InchesToPoints(6), _
Alignment:=wdAlignTabRight, _
Leader:=wdTabLeaderDots
End With
For Each bk In ActiveDocument.Range.Bookmarks
rg.Text = bk.Name & vbTab
rg.Collapse wdCollapseEnd
ActiveDocument.Hyperlinks.Add _
Anchor:=rg, _
Address:=ActiveDocument.Name, _
SubAddress:=bk.Name, _
TextToDisplay:=bk.Range.Information( _
wdActiveEndAdjustedPageNumber)
Set rg = ActiveDocument.Range
rg.Collapse wdCollapseEnd
rg.InsertBefore vbCr
rg.Collapse wdCollapseEnd
Next
End Sub
--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.