Find the last opened instance of Word

K

Kathy Webster

I'm running vb code from MSAccess. I want the code to find the last opened
window of Word and do something to the document that is on that Word screen.

Help!
TIA,
Kathy
 
F

fumei via OfficeKB.com

What do you mean by "last opened"?

ActiveDocument is the object for the active document.
 
K

Kathy Webster

Each time you open a document in word, it opens each document in a separate
window. I want to write VB code that will go to the last window/document
that was opened by word. The code will be starting from Microsoft Access.
 
D

Doug Robbins - Word MVP

You would probably be better off having your Access code create a new
document for whatever purpose it is required.

In Access

Dim appWord As Word.Application
Dim doc As Word.Document
'Avoid error 429, when Word isn't open.
On Error Resume Next
Err.Clear
'Set appWord object variable to running instance of Word.
Set appWord = GetObject(, "Word.Application")
If Err.Number <> 0 Then
'If Word isn't open, create a new instance of Word.
Set appWord = New Word.Application
End If
Set doc = appWord.Documents.Add("Template Path\Name")
With doc
'Whatever you want to do with the document
End With
Set doc = Nothing
Set appWord = Nothing



--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

Kathy Webster said:
Each time you open a document in word, it opens each document in a
separate window. I want to write VB code that will go to the last
window/document that was opened by word. The code will be starting from
Microsoft Access.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top