Opening a .doc from code

S

Stanley

I am trying to open a Word document from an Access program using the
following code:
objWord.Documents.Open path\FileName
objWord.Documents(1).Activate
I can't get the Word document open on my desktop.
What am I doing wrong?
Thanks,
Stanley
 
D

Doug Robbins - Word MVP

You should show us all of the code so that we can see what you have set
objWord to.

Assuming that you have used something like

Set objWord = GetObject(, "Word.Application")

or

Set objWord = CreateObject("Word.Application")

then having declared docWord as a Word.Document, try

Set docWord = objWord.Documents.Open("path\File")
docWord.Activate

--
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, originally posted via msnews.microsoft.com
 
F

Fumei2 via OfficeKB.com

Set docWord = objWord.Documents.Open("path\File")

as long as it is not followed by any instructions on another document, does
not require an Activate.

It makes the just opened document the ActiveDocument. Further, in most cases
Activate is not even needed, as working with the document object (docWord)
allows access to all properties of the document.
You should show us all of the code so that we can see what you have set
objWord to.

Assuming that you have used something like

Set objWord = GetObject(, "Word.Application")

or

Set objWord = CreateObject("Word.Application")

then having declared docWord as a Word.Document, try

Set docWord = objWord.Documents.Open("path\File")
docWord.Activate
I am trying to open a Word document from an Access program using the
following code:
[quoted text clipped - 4 lines]
Thanks,
Stanley
 

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