Open Goto-Bookmark

W

WolfgangJ

Hi,

I would like to use a macro just to open the
"go to a bookmark" feature of Word.

If I record a macro then it always goes to a SPECIFIC bookmark
e.g. "finance". Otherwise the macro-recorder doesn't record anything.
How do I modify the recorded macro ?
Enclosed the recorded macro

Thank you,
Wolfgang


Sub textMarker()
Selection.GoTo What:=wdGoToBookmark, Name:="finance"
Selection.Find.ClearFormatting
With Selection.Find
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
End Sub
 
J

Jay Freedman

Hi Wolfgang,

The recorder is... stupid. I wrote a whole article about its shortcomings
(http://www.word.mvps.org/FAQs/MacrosVBA/ModifyRecordedMacro.htm).
Everything from Selection.Find to End With is total garbage, of no use to
anyone. The fact that the recorder puts it there is a bug.

First, you'll need a way to get the name of the desired bookmark into the
macro. If you use an InputBox command as shown below, you'll have to type in
the entire name and not make any mistakes, or else it won't find the
bookmark. The macro below handles this by repeatedly showing the InputBox
until you either type an existing name or cancel (or press Enter with an
empty entry).

To be able to show a list of existing bookmarks and let you choose one,
you'll have to make a UserForm and put a listbox on it, plus the code to
"read" the selection and act on it -- not hard, but a bit more than I want
to cover in a newsgroup post.

You'll never get anything like this macro from the recorder:

Sub GoToBookmark()
Dim BKname As String
While Not ActiveDocument.Bookmarks.Exists(BKname)
BKname = InputBox("Name:", "Go To Bookmark")
If Trim(BKname) = "" Then Exit Sub
Wend
ActiveDocument.Bookmarks(BKname).Range.Select
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