Another "word doc from a button" thread

vangogh228

Registered User.
Local time
Today, 13:04
Joined
Apr 19, 2002
Messages
302
Hello all.

I'm trying to open a document from a button on a form... as many others have done. Here's my code, that I based on successful code that opens an excel spreadsheet (edited as well as I could figure out for word)... but it fails on the Set objWdDoc line. Any help is greatly appreciated.

Dim objWdApp As Object
Dim objWdDoc As Object
Set objWdApp = CreateObject("Word.Application")
Set objWdDoc = objWdApp.Documents.Open("\\dbdfile\ARSupport$\Projects\" & Forms!ProjectMainForm.ProjectName.Value & " - MD50.doc")
objWdApp.Visible = True


(((The space displayed in the path in the middle of the word "Projects" is a display error here.)))


Thanks again.
Tom
 
Hi,

Try using the shell function as follows:

Code:
If Shell("C:\Program Files\Microsoft Office\Office\WORD.EXE", vbMaximizedFocus) = 0 Then

MsgBox "Failed to open MS Word"

End If

If you replace the C:\.... string with the location of your file this should work.
 
Hello all.

I'm trying to open a document from a button on a form... as many others have done. Here's my code, that I based on successful code that opens an excel spreadsheet (edited as well as I could figure out for word)... but it fails on the Set objWdDoc line. Any help is greatly appreciated.

Dim objWdApp As Object
Dim objWdDoc As Object
Set objWdApp = CreateObject("Word.Application")
Set objWdDoc = objWdApp.Documents.Open("\\dbdfile\ARSupport$\Projects\" & Forms!ProjectMainForm.ProjectName.Value & " - MD50.doc")
objWdApp.Visible = True


(((The space displayed in the path in the middle of the word "Projects" is a display error here.)))


Thanks again.
Tom

If you are using late binding like this, you need to create the objWdDoc object. Nowhere are you creating it. You have to create it before assigning it. So add in
Set objWdDoc = CreateObject("Word.Document")

before the point where you try to assign it a document.
 
THANK YOU !!! Works great. I will add this to my code bank.
 

Users who are viewing this thread

Back
Top Bottom