Ctrl + Up / Down are supposed to jump to previous / last bookmarks.
It kind of works: we move location in the file, but MS Word's numbering of bookmarks doesn't seem to reflect the ordering in the file itself. If anyone has ideas on how to improve, that would be fantastic.
Code: Select all
#IfWinActive ahk_exe winword.exe
; Navigate to next and previous bookmarks
^Up:: ; jump to previous bookmark
oWord :=ComObjActive("Word.Application")
bookmark_count := oWord.ActiveDocument.Bookmarks.count
if(! bookmark_count) { ; first use of the script: jump to first
current_bookmark := 1
oWord.ActiveDocument.Bookmarks(Index := 1).select
}
else {
first_bookmark := (current_bookmark == 1)
if (first_bookmark) {
oWord.ActiveDocument.Bookmarks(Index := bookmark_count).select ; jump to last
current_bookmark := bookmark_count
}
else {
current_bookmark--
oWord.ActiveDocument.Bookmarks(Index := current_bookmark).select
}
}
oWord := ""
return
^Down:: ; jump to next bookmark
oWord :=ComObjActive("Word.Application")
bookmark_count := oWord.ActiveDocument.Bookmarks.count
if(! bookmark_count) { ; first use of the script: jump to last
current_bookmark := bookmark_count
oWord.ActiveDocument.Bookmarks(Index := current_bookmark).select
}
else {
last_bookmark := (current_bookmark == bookmark_count)
if (last_bookmark) {
oWord.ActiveDocument.Bookmarks(Index := 1).select ; jump to first
current_bookmark := 1
}
else {
current_bookmark++
oWord.ActiveDocument.Bookmarks(Index := current_bookmark).select
}
}
oWord := ""
return
#IfWinActive