Hyperlink to the next(or previous) bookmark

D

Dan Perkins

I know how to add a hyperlink to a bookmark, and I know that I can use
Selection.Goto to move to the next or previous bookmark in my document, what
I want to do is somehow combine these so that when the user clicks on the
hyperlink it will goto the next or previous bookmark.
How can I do this?
 
D

Dave Lett

Hi Dan,

You can use something like the following:

Dim lBkMk As Long

lBkMk = ActiveDocument.Range(0,
Selection.Paragraphs(1).Range.End).Bookmarks.Count
With Selection.Hyperlinks
.Add _
Anchor:=Selection.Range, _
SubAddress:=ActiveDocument.Range.Bookmarks(lBkMk), _
ScreenTip:="GoTo Previous Bookmark", _
TextToDisplay:="Previous bookmark"
Selection.TypeParagraph
.Add _
Anchor:=Selection.Range, _
SubAddress:=ActiveDocument.Range.Bookmarks(lBkMk + 1), _
ScreenTip:="GoTo Next Bookmark", _
TextToDisplay:="Next bookmark"
End With

HTH,
Dave
 
D

Dan Perkins

Ok, I got that to work, sort of.

Let me better explain what I am trying to do and that might help

I have a document with program source code. This code contains changes to
the original made by me and by others. In order for another programmer to
verify my changes, they need to know what changes are mine. So, we have a
document that lists all of the source code for our task, we then go and
highlight our changes to the source code.
What I am trying to do is to make that task a little simpler by providing
links to the changes in the source code. This means that as I find each
change, I am adding in a bookmark, highlighting the change and adding a
hyperlink from the top of the document to that bookmark. Then I want to add a
hyperlink from the current bookmark to the next bookmark, the previous
bookmark, and the top of the document.

The solution you suggested works great when I add the first hyperlink to
next and previous, but adding in a second one does not change the bookmark
that the first hyperlink points to. I am guessing that I need to somehow
refresh the hyperlink settings or something like that.

Thanks again for the help
 
D

Dave Lett

Hi Dan,

Inserting hyperlinks like this is not dynamic, so we should expect the
previous hyperlinks to insert in the same manner. You can certainly create a
system that inserts a group of hyperlinks based on some condition that you
control.

Are you sure that you're using the correct tool? After all, you could be
using the Track Changes feature and skip the VBA completely. The Track
Changes feature will allow your user to browse each change, and Word
controls/updates when a change is accepted or rejected.

It won't create a table of contents for your changes. However, you can
insert your changes with a custom style and create a table of contents based
on that style. For example:
{ TOC \t "InsertedChanges,1" }

HTH,
Dave
 
D

Dan Perkins

Dave,
Thanks, I get so caught up in thinking of programming solutions that I
sometimes overlook the obvious. I think that using track revisions would
certainly make this easier.
I will still need to do this via a macro app, but from what I see, I should
be able to mark text add inserted, changed, or deleted. A quick test makes it
look like the revisions are dynamic so using the NextRevision and
PreviousRevision Methods would all me to easily jump between them.
 

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