Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Code to Open Document in Word

Status
Not open for further replies.

jvhazelbaker

Programmer
Dec 15, 2004
38
0
0
US
I am trying to run a Word document when clicking a button on an Access form. The code I am using is:

________________________________________________________
Private Sub Command16_Click()

Dim LWordDoc As String
Dim oApp As Object

'Path to the word document
LWordDoc = "s:\red\homeplace\standards.doc"

If Dir(LWordDoc) = "" Then
MsgBox "Document not found."

Else
'Create an instance of MS Word
Set oApp = CreateObject(Class:="Word.Application")
oApp.Visible = True

'Open the Document
oApp.Documents.Open filename:=LWordDoc
End If

End Sub
_____________________________________________________

When I click the button, I receive the error:

_____________________________________________________

Run Time Error '-2147024770(8007007e)':
Automation Error
The specified module could not be found.
_____________________________________________________

When I click 'debug' this line in the code is highlighted:

Set oApp = CreateObject(Class:="Word.Application")

I don't know what could be wrong with the code. It was working fine. Any ideas?

 
And what about something like this ?
Else
'Create an instance of MS Word
Set oApp = GetObject(LWordDoc)
oApp.Application.Visible = True
Set oApp = Nothing
End If


Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Unfortunately that didn't work. Nothing happened when I clicked the button. Thanks though.
 
Even after a reboot ?
If so repair your ms-office installation.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Try this first:

change Set oApp = CreateObject(Class:="Word.Application")
to Set oApp = CreateObject("Word.Application")

 
Here is what I use:
Code:
Dim stAppName As String
Dim stPathA As String
Dim stPathB As String
Dim stCombinedPath As String

stPathA = SysCmd(acSysCmdAccessDir)
stAppName = "WINWORD.EXE "
stPathB = "PathToYourWordFile.doc"
stCombinedPath = stPathA & stAppName & stPathB 
Call Shell(stCombinedPath, 1)

Hope this helps.
Jay
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top