#1
|
|||
|
|||
vba to go to next bookmark
Hi all,
I have a word document with some tables to keep some structure to a word document. I have inserted some bookmarks in the word document. Now what I need is that when I press a keyboard shortcut, it will jump to the next bookmark. Every time I press the shortcut, it should move to the next bookmark. Any help would be really great. Thanks in advance. Greetings. |
#2
|
||||
|
||||
A google search uncovered the following code:
Code:
Option Explicit Sub FindNextBookmark() Dim oBookmark As Bookmark Dim nCurrentPosition As Long Dim nPosition As Long Dim nFirstPosition As Long Dim sFirstBookmark As String Dim nNextPosition As Long Dim sNextBookmark As String Dim oRng As Range If Documents.Count > 0 Then Set oRng = Selection.Range nCurrentPosition = Selection.Range.Start nNextPosition = 0 nFirstPosition = 0 For Each oBookmark In ActiveDocument.Bookmarks nPosition = oBookmark.Start If nFirstPosition = 0 _ Or nPosition < nFirstPosition Then nFirstPosition = nPosition sFirstBookmark = oBookmark.name End If If nPosition > nCurrentPosition _ And (nPosition < nNextPosition _ Or nNextPosition = 0) Then nNextPosition = nPosition sNextBookmark = oBookmark.name End If Next oBookmark If nNextPosition > 0 Then ActiveDocument.Bookmarks(sNextBookmark).Range.Select ElseIf nFirstPosition > 0 Then ActiveDocument.Bookmarks(sFirstBookmark).Range.Select End If oRng.End = Selection.Range.End End If MsgBox oRng End Sub |
#3
|
|||
|
|||
Hi Jp,
Thanks for the code. I will try it out as soon as I can. BIG thanks. |
Thread Tools | |
Display Modes | |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Creating TOC using Add Bookmark | davidku | Word | 4 | 01-27-2014 01:49 AM |
VBA to insert Bookmark | rockwellsba | Word VBA | 2 | 05-31-2011 01:07 AM |
Bookmark Classification | DrDoom | Word | 0 | 06-29-2010 07:08 AM |
Bookmark to another document | spqr | Word | 3 | 06-26-2009 04:51 AM |