Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 06-06-2014, 01:10 AM
megatronixs megatronixs is offline vba to go to next bookmark Windows XP vba to go to next bookmark Office 2003
Advanced Beginner
vba to go to next bookmark
 
Join Date: Aug 2012
Posts: 42
megatronixs is on a distinguished road
Default 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.
Reply With Quote
  #2  
Old 06-06-2014, 09:56 AM
jpb103's Avatar
jpb103 jpb103 is offline vba to go to next bookmark Windows 7 64bit vba to go to next bookmark Office 2007
Advanced Beginner
 
Join Date: May 2014
Location: Thunder Bay, Ontario
Posts: 58
jpb103 is on a distinguished road
Default

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
Reply With Quote
  #3  
Old 06-08-2014, 09:53 PM
megatronixs megatronixs is offline vba to go to next bookmark Windows XP vba to go to next bookmark Office 2003
Advanced Beginner
vba to go to next bookmark
 
Join Date: Aug 2012
Posts: 42
megatronixs is on a distinguished road
Default

Hi Jp,

Thanks for the code. I will try it out as soon as I can.

BIG thanks.
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
vba to go to next bookmark Creating TOC using Add Bookmark davidku Word 4 01-27-2014 01:49 AM
vba to go to next bookmark 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

Other Forums: Access Forums

All times are GMT -7. The time now is 06:40 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft