INDEX of BOOKMARKS

N

NJK

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.

----------------
This post is a suggestion for Microsoft, and Microsoft responds to the
suggestions with the most votes. To vote for this suggestion, click the "I
Agree" button in the message pane. If you do not see the button, follow this
link to open the suggestion in the Microsoft Web-based Newsreader and then
click "I Agree" in the message pane.

http://www.microsoft.com/office/com...6265bb&dg=microsoft.public.word.docmanagement
 
J

Jay Freedman

NJK said:
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):

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.5), _
Alignment:=wdAlignTabRight, _
Leader:=wdTabLeaderDots
End With

For Each bk In ActiveDocument.Range.Bookmarks
rg.Text = bk.Name & vbTab & _
bk.Range.Information(wdActiveEndAdjustedPageNumber) _
& 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.
 
J

Jay Freedman

Jay said:
NJK said:
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.
 
D

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 said:
Jay said:
NJK said:
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.
 
J

Jay Freedman

To show the text of the bookmark, replace the line

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?


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 said:
Jay said:
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.
 
D

DeanH

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

Jay Freedman said:
To show the text of the bookmark, replace the line

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?


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 said:
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.
 
J

Jay Freedman

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

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

Jay Freedman said:
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?


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

DeanH

Fantastic, Jay.
Does exactly as required and will save me so much time.
All the best
DeanH


Jay Freedman said:
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

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

Jay Freedman said:
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.
 
D

DeanH

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


DeanH said:
Fantastic, Jay.
Does exactly as required and will save me so much time.
All the best
DeanH


Jay Freedman said:
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

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

Jay Freedman

Hi Dean,

It's only a small change. The arguments of the ActiveDocument.Fields.Add
command are fairly similar to those of the ActiveDocument.Hyperlinks.Add
command.

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.Fields.Add _
Range:=.Range, _
Type:=wdFieldRef, _
Text:=bk.Name & " \h", _
PreserveFormatting:=False
.TypeParagraph
Next
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.
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


DeanH said:
Fantastic, Jay.
Does exactly as required and will save me so much time.
All the best
DeanH


Jay Freedman said:
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.
 
D

DeanH

Many thanks Jay.
I will give this a go next week when I am back in the office.
Have a great weekend.
Ciao
DeanH


Jay Freedman said:
Hi Dean,

It's only a small change. The arguments of the ActiveDocument.Fields.Add
command are fairly similar to those of the ActiveDocument.Hyperlinks.Add
command.

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.Fields.Add _
Range:=.Range, _
Type:=wdFieldRef, _
Text:=bk.Name & " \h", _
PreserveFormatting:=False
.TypeParagraph
Next
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.
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


DeanH said:
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.
 
D

DeanH

Jay, works beautifully, many thanks
All the best
DeanH


DeanH said:
Many thanks Jay.
I will give this a go next week when I am back in the office.
Have a great weekend.
Ciao
DeanH


Jay Freedman said:
Hi Dean,

It's only a small change. The arguments of the ActiveDocument.Fields.Add
command are fairly similar to those of the ActiveDocument.Hyperlinks.Add
command.

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.Fields.Add _
Range:=.Range, _
Type:=wdFieldRef, _
Text:=bk.Name & " \h", _
PreserveFormatting:=False
.TypeParagraph
Next
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.
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.
 
T

terryc

I'd like to be able to check my bookmark names but I don't understand
anything about entering the code you've written below. I'm totally lost when
I look at gmayor.com! Is there a Word 2007 feature that would just show the
name on the screen and when I print the document?

Jay Freedman said:
NJK said:
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):

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.5), _
Alignment:=wdAlignTabRight, _
Leader:=wdTabLeaderDots
End With

For Each bk In ActiveDocument.Range.Bookmarks
rg.Text = bk.Name & vbTab & _
bk.Range.Information(wdActiveEndAdjustedPageNumber) _
& 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.
 
S

Suzanne S. Barnhill

If you go to Insert | Links | Bookmark, the dialog shows the existing
bookmarks.

--
Suzanne S. Barnhill
Microsoft MVP (Word)
Words into Type
Fairhope, Alabama USA
http://word.mvps.org

terryc said:
I'd like to be able to check my bookmark names but I don't understand
anything about entering the code you've written below. I'm totally lost
when
I look at gmayor.com! Is there a Word 2007 feature that would just show
the
name on the screen and when I print the document?

Jay Freedman said:
NJK said:
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):

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.5), _
Alignment:=wdAlignTabRight, _
Leader:=wdTabLeaderDots
End With

For Each bk In ActiveDocument.Range.Bookmarks
rg.Text = bk.Name & vbTab & _
bk.Range.Information(wdActiveEndAdjustedPageNumber) _
& 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.
 

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