wdGoToNext and moving between bookmarks

W

Wespa

Hi.
Why dont this code work.
ActiveDocument.GoTo what:=wdGoToBookmark which:=wdGoToNext

Is it possible to jump between bokmarks without knowing ther name ?
 
H

Helmut Weber

Hi Wespa,
I don't know why. Like so many things things,
it should work, but doesn't.
Here comes a workaround:
Sub Test445()
' next bookmark
On Error GoTo finish
Dim r As Range
Selection.Collapse direction:=wdCollapseEnd
Set r = Selection.Range
If r.start = r.End Then
r.start = r.start + 1
End If
r.End = ActiveDocument.Range.End
r.Bookmarks(1).Select
Exit Sub
finish:
MsgBox "no more bookmarks"
End Sub
' ---
Sub Test446()
' previous bookmark
On Error GoTo finish
Dim r As Range
Selection.Collapse direction:=wdCollapseStart
Set r = Selection.Range
r.start = 0
r.Bookmarks(r.Bookmarks.Count).Select
Exit Sub
finish:
MsgBox "no more bookmarks"
End Sub
---
Greetings from Bavaria, Germany
Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word XP, Win 98
http://word.mvps.org/
 
K

Klaus Linke

Hi Helmut, Wespa,

I fought with this too. If you have overlapping bookmarks, it gets terribly
messy (if you don't want to miss some bookmarks, or risk ending up in a
loop).
I guess the Word programmers ran into the same problem, and gave up.

Regards,
Klaus
 

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