Answered by:
From withing Access VBA, how to open a Word document to a specific paragraph or bookmark

Question
-
In my Access program, I need to open a large Word document. Now, I am able to open Word with a document from within Access program. My question is: I want to position the cursor to a specific line, or bookmark, or section, so that the user does not have to do it himself, thus saving his time. The Access program will have the info needed for the seek operation, such as part of a sentence, or a bookmark, or whatever is needed to speed up the seek in Word.
Any help is appreciated.
Sunday, April 19, 2020 6:26 AM
Answers
-
I assume that you create a Word.Application object in your code; let's say it is named objWord.
The following line goes to the bookmark named Test in the active document:
objWord.Selection.GoTo What:=-1, Name:="Test"
(-1 = wdGoToBookmark)
To go to line 120:
objWord.Selection.GoTo What:=3, Which:=1, Count:=120
(3 = wdGoToLine, 1 = wdGoToAbsolute)
See https://docs.microsoft.com/en-us/office/vba/api/word.selection.goto for more info.
Regards, Hans Vogelaar (http://www.eileenslounge.com)
- Marked as answer by Nkb1000 Sunday, April 19, 2020 11:50 AM
- Edited by Hans Vogelaar MVPMVP Sunday, April 19, 2020 12:21 PM
Sunday, April 19, 2020 8:03 AM
All replies
-
Hi Nkb1000,
I'd like to know why you use Access VBA to open a Word document and how the user can specify a line, or bookmark, or section. Generally speaking, I'd like to know your situation about your issue.
Regards,Ashidacchi -- http://hokusosha.com
Sunday, April 19, 2020 7:01 AM -
Hi Nkb1000,
I'd like to know why you use Access VBA to open a Word document and how the user can specify a line, or bookmark, or section. Generally speaking, I'd like to know your situation about your issue.
Regards,
Ashidacchi -- http://hokusosha.com
To answer your question, part of my Access program is to maintain and manage a number of Word documents. A user may wish to open a specific Word document, do necessary editing, if the situation warrants, save and close the file. Editing Word documents is essential in my Access program. The Access program also maintains other important records which is also related to the info in Word files.
Word documents have sections, headings, and sub headings, etc.. In Access, the database, keeps, the name of the file, its location, and other info needed to perform the seek once a Word file is open. Currently, I can open a Word document, but I do not know how to open it to a specific location.
I hope this answers your question.
Sunday, April 19, 2020 7:39 AM -
I assume that you create a Word.Application object in your code; let's say it is named objWord.
The following line goes to the bookmark named Test in the active document:
objWord.Selection.GoTo What:=-1, Name:="Test"
(-1 = wdGoToBookmark)
To go to line 120:
objWord.Selection.GoTo What:=3, Which:=1, Count:=120
(3 = wdGoToLine, 1 = wdGoToAbsolute)
See https://docs.microsoft.com/en-us/office/vba/api/word.selection.goto for more info.
Regards, Hans Vogelaar (http://www.eileenslounge.com)
- Marked as answer by Nkb1000 Sunday, April 19, 2020 11:50 AM
- Edited by Hans Vogelaar MVPMVP Sunday, April 19, 2020 12:21 PM
Sunday, April 19, 2020 8:03 AM -
Great. Good job.
Hans, you always come to the rescue!!!
Thank you Hans.
Sunday, April 19, 2020 11:50 AM