VB GetObject Function

J

Jana

I want to open a Word document via a command button on an
Access form. I'm using Access 2000. So far I've created
the command button with the following code:
Private Sub GdBkdoc1_Click()
On Error GoTo Err_GdBkdoc1_Click

Dim oWordFile As Object

Set oWordFile = GetObject
("c:\test.doc", "Word.Application")
oWordFile.Visible = True

Exit_GdBkdoc1_Click:
Exit Sub

Err_GdBkdoc1_Click:
MsgBox Err.Description
Resume Exit_GdBkdoc1_Click

End Sub
I receive the following error when the function runs:
Filename or class name not found during Automation
operation.
If I take out the filename in the above code, Word opens
fine.
What am I missing? All help will be appreciated!!

Thanks,
Jana
 
G

gisela

This worked for me..

------ more code -------

'strApp: Word o Excel?
'strPath: filename
Dim MyObject As Object
On Error GoTo Err_EnviaInfo
Dim ObjectWasNotRunning As Boolean
On Error Resume Next
Set MyObject = GetObject(, strApp)
If Err.Number <> 0 Then ObjectWasNotRunning = True
Err.Clear
Set MyObject = GetObject(strPath)
If MyObject Is Nothing Then
MsgBox "Invalid Path"
Exit Function
End If
MyObject.Application.Visible = True

If ObjectWasNotRunning = True Then
MyObject.Parent.Windows(1).Visible = True
End If

If strApp = "Word.Application" Then ' Microsoft Word
MyObject.Application.documents(strPath).Activate

-------- more code ---------
hope it's help you
gisela
 
J

Jana

It worked for me as well. I did have to tweek it a bit
(see the capitalized text below).

Thanks!
Jana
 

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