Bookmark Listing

C

Casey Mac

Greetings,

What im looking for is a bit of code so that once a selection is made (user
selects text) a macro can be run that displays all the bookmarks in the
current document. The user selects the appropirate bookmark for the
selected text and then that selection gets applied to the selected text as a
hyperlink. ie #bookmark.


Sub Macro1()

ActiveDocument.Hyperlinks.Add Anchor:=Selection.Range, Address:="",
SubAddress:=" ",

End Sub
 
G

Greg Maxey

Greg has been busy posting refinements thanks to suggestions from Helmut and
Graham and his own stumbling about in the dark.

I have revised the code to show messages and alerts using either the Office
Assistant or traditional message boxes. I also thought it would be nice to
add a method to throw in a quick bookmark with the click of a button. The
added "Quick Mark" button inserts a sequentially numbered bookmark at the
selection.

One of the gentlemen named above was so forward as to suggest spelling
corrections. Those are made, but I am prone to error so there could be
more.

The web page was just updated so visit:
http://gregmaxey.mvps.org/Bookmark_Tool.htm
for a look see. Constructive comments always welcomed.
 
C

Casey Mac

I did take look at the site and unfortunatly it is way over my head (VBA
wise) as well as it doesnt do exactly what i want. The code below asks a
user for a word to find and then a hyperlink to insert. Then what name to
give that hyperlink. So essentially its a find/replace. my issue is, the
hyperlink that im getting the user to input is really a name of a file
(relative link to a file). Works great for external links. I then got to
thinking that there as some places in the document i would like to link to.
So if i some how could insert the names of all the book marks and choose the
on i wanted i would have a link internal to the document. What would be
equally usefull would be to bring up the book mark screen that comes up when
you want to instert a bookmark.

Do you think this is possible or am i just a dreamer?


Sub FindReplaceYesNo()
Dim rDoc As Range ' range replace
Dim sFnd As String ' string to be found
Dim sHpl As String ' hyperlink
Dim sDsp As String ' hyperlink display
Dim iCount As Integer ' Replace Count
sFnd = InputBox("Enter the word you wish to replace with a hyperlink:")
sHpl = InputBox("Enter File Name:")
sDsp = InputBox("Enter the HyperLink display name")
Set rDoc = ActiveDocument.Range
With rDoc.Find
iCount = 0
.Text = sFnd
.Wrap = wdFindStop
Do While .Execute
iCount = iCount + 1
rDoc.Select
If MsgBox("Replace Highlighted Selection?", vbYesNo, "Replace Text")
= vbYes Then
ActiveDocument.Hyperlinks.Add _
rDoc, sHpl, TextToDisplay:=sDsp
rDoc.End = rDoc.End + Len(sDsp)
rDoc.Collapse wdCollapseEnd
End If
Loop
End With
If iCount > 0 Then
MsgBox "Number of Highlighted Words Found = " & iCount, vbInformation,
"Results Box"

End If
End Sub
 
G

Greg Maxey

Casey Mac,

Yes I think it is doable. Granted the code on my website is a spider web
and complex. That is mainly because I am a amateur and don't know any
better. Still it creates a list of all bookmarks in the document. All you
have to do is replicate that feature to give you a screen to pick the
bookmark name from. Just start in the module "Bookmarker" with the routine
"Open Bookmarker" and step through the sequence. You will see how the
listbox is populated with each bookmark name.

HTH
 
C

Casey Mac

ill give it a shot. Thanks for your words of encouragement. if anyone else
wants to try I would welcome there code. Ill post something in the next few
hours to see what you all think.

cheers from Canada

cmac
 

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