ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   goto in Word (https://www.excelbanter.com/excel-programming/275863-goto-word.html)

Philipp Schramek

goto in Word
 
Hi
I want to open a word file and go to a specific bookmark in word.
Therefore I wrote the code you see below.

....
Private Sub CommandButton1_Click()
Dim wrdApp As Word.Application
Dim wrdDoc As Word.Document

Set wrdApp = CreateObject("Word.Application")
wrdApp.Visible = True
Set wrdDoc = wrdApp.Documents.Open("S:\Folder\File.doc")
wrdDoc.GoTo What:=wdGoToBookmark, Name:="SomeText"
End Sub
....

My problem is that it works as far as it opens the file but it does not
go to the position I told to, or at least it does not scroll there. In
Word-VBA a "scroll = true" option is not given like in Excel-VBA.

Additionally I would like to check whether the file is already open
before opening it again. I could not find out yet how to check whether a
file is already open or not.

Does anyone have some advise.
Thanks Philipp


Steve Yandl[_3_]

goto in Word
 
To check if Word is already open, this article might give you an idea:
http://www.mvps.org/word/FAQs/InterD...WordFromXL.htm

To get to your bookmark, you might try
wrdDoc.Bookmarks("SomeText").Range.Select

Steve


"Philipp Schramek" wrote in message
...
Hi
I want to open a word file and go to a specific bookmark in word.
Therefore I wrote the code you see below.

...
Private Sub CommandButton1_Click()
Dim wrdApp As Word.Application
Dim wrdDoc As Word.Document

Set wrdApp = CreateObject("Word.Application")
wrdApp.Visible = True
Set wrdDoc = wrdApp.Documents.Open("S:\Folder\File.doc")
wrdDoc.GoTo What:=wdGoToBookmark, Name:="SomeText"
End Sub
...

My problem is that it works as far as it opens the file but it does not
go to the position I told to, or at least it does not scroll there. In
Word-VBA a "scroll = true" option is not given like in Excel-VBA.

Additionally I would like to check whether the file is already open
before opening it again. I could not find out yet how to check whether a
file is already open or not.

Does anyone have some advise.
Thanks Philipp





All times are GMT +1. The time now is 10:41 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com