Open Application

  • Thread starter Thread starter JethroUK
  • Start date Start date
J

JethroUK

Anyone see why this wont work?:

Dim oApp As Object

Set oApp = GetObject("InviteToInduction.doc", "Word.Application")
oApp.Visible = True

I get 'classname not found' - Tried it without the class:

Set oApp = GetObject("InviteToInduction.doc")

Get 'invalid syntax'

Filename is correct - Not using a path because the file is local (Tried it
with full path - still no go) - CreateObject works with new app
 
I haven't done a lot of Word automation, and none recently. However, the
help file says that the first, "pathname" argument must be the full path and
name of the document, so unless someone knows different I wouldn't expect
the file name alone to work. And I'd expect a reference to a Word document
to return a Word.Document object instead of a Word.Application document. The
following test code seems to bear this out ...

Public Sub TestGetObject()

Dim objApp As Object
Dim objDoc As Object

Set objDoc = GetObject("c:\documents and settings\brendan reynolds\" & _
"my documents\doc1.doc")
Debug.Print objDoc.Name
Set objApp = objDoc.Parent
Debug.Print objApp.Name

Set objDoc = Nothing
Set objApp = Nothing

End Sub

Result in the Immediate window ...
testgetobject
Doc1.doc
Microsoft Word
 
i tried your code as is (except the path):

Private Sub Invite_Click()
Dim objApp As Object
Dim objDoc As Object

Set objDoc = GetObject("u:\!Clait2006\CLAIT2006
database\Congratulations.doc")
Debug.Print objDoc.Name
Set objApp = objDoc.Parent
Debug.Print objApp.Name

Set objDoc = Nothing
Set objApp = Nothing

End Sub

Nothing - No Error msg - No document - No Debug window

Tried it on 2 machines - nothing - I cant figure whats wrong - I'll check
the my installation - Many Thanks
 
You didn't mention which version(s) of Access and Word you are using.

When I began running into issues opening Word documents from within Access,
I ended up using the hyperlink to method to open the document. That's been
working so far...

Regards

Jeff Boyce
<Office/Access MVP>
 
The code isn't intended to display a document, only to demonstrate that
GetObject(full path/name of Word document) returns a Word.Document object,
not a Word.Application object, and that you can retrieve the Application
object using the Parent property of the Document object. So 'no error
message' and 'no document' are both as expected.

The Debug window and the Immediate window are the same window. The code was
designed to be executed from the Immediate window. You must have executed it
some other way, as I see you have changed my original procedure
declaration - you've changed 'Public' to 'Private'. You'll need to change it
back to Public to execute the code from the Immediate window, and ensure
that you have pasted the code into a standard module, not a class module
(this includes form and report modules). Alternatively, modify the code to
display message boxes instead of writing to the Debug/Immediate window ...

Public Sub TestGetObject()

Dim objApp As Object
Dim objDoc As Object

Set objDoc = GetObject("u:\!Clait2006\CLAIT2006
database\Congratulations.doc")
MsgBox objDoc.Name
Set objApp = objDoc.Parent
MsgBox objApp.Name

Set objDoc = Nothing
Set objApp = Nothing

End Sub
 
i've never used debug window - i dont do much programming - but it works now
thanks - my original error was in:

objDoc.Visible = True

i was getting an error - i took the line out and couldn't see anything, when
i really only needed to put :

objDoc.Application.Visible = True

bit disappointed about having to put the absolute path when a relative path
would make it more portable (i'm working on several machines) oh hum - glad
it's sorted, i've planned about 5-6 mail-merges out of the database so i was
a bit concerned - thanks again
 
Back
Top