printout method on embedded word document fails

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a word document embedded in an excel worksheet

when i try to print the document from vba i get an automation error.

my code is something like this

sub test()
dim owordapp as word.application
dim oworddoc as word.document
dim oembobj as oleobject

set oembobj=thisworkbook.somesheet.oleobjects("mydoc")
oembobj.activate

set owordapp=oembobj.object.application
set oworddoc=owordapp.activedocument

oworddoc.printout

......
end sub

using office 2003 on xp sp2 system
 
This works for me, using late binding. I have not tested much and no error
handling used:

Private Sub CommandButton1_Click()
Dim WordDoc As OLEObject
Dim WordApp As Object

Set WordDoc = ActiveSheet.OLEObjects(1)

With WordDoc
.Activate
Set WordApp = .Object.Application
End With

With WordApp
With .activedocument
.PrintOut
.Close False
End With
.Quit
End With

End Sub

NickHK
 
Thanks NickHK,


works fine.
So adressing the OLEobject via its "object" property doesn't work ?
 
I am never sure with an OLEObject when to use .Parent, .Object or
..Application. After some trial and error I get something to work, but the
help seems lacking in this area.
Maybe someone has a link that document this ?

NickHK
 
Hi NICKHK,

looks like i was to fast with my response,

now I get a "runtime error 4605 - method not available" on the printout
statement

i' m running slightly insane here. have invested already 2 days in this
undocumented problem

hope you have the answer

thanks
 
Works for me.
Are you sure you are using the correct syntax, with all the correct "." in
place. Try:
WordApp.Activedocument.PrintOut

NickHK
 

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

Back
Top