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!

Print an OLE object

Status
Not open for further replies.

1DMF

Programmer
Jan 18, 2005
8,795
0
0
GB
How can I print an OLE object document?

I have tried ('Office' is an unbound OLE frame)

Code:
Set oDoc = Me.Office.Object.Application
oDoc.PrintOut Background:=False

That just errors with
This method or property is not available because this document is being edited in another application

So I tried it when the document isn't 'activated' but that errors with
Automation Error : The object invoked has disconnected from it's clients.

This KB :
Shows what I'm already doing other than the verb being Open and I'm using Show.

Why can't I print the word document from the OLE object?


"In complete darkness we are all the same, it is only our knowledge and wisdom that separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"
Free Electronic Dance Music
 
Well it seems it is impossible to print an active document that is open via OLE.

I've got it working by having to close it (deactivate) , then change the verb to open so the the document opens externally in word, reactivate it and print then quit the document.

Code:
    Me.Office.Verb = acOLEVerbOpen
    Me.Office.Action = acOLEActivate
    Me.Office.Object.Application.PrintOut Background:=False
    Me.Office.Object.Application.Quit

[banghead]

"In complete darkness we are all the same, it is only our knowledge and wisdom that separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"
Free Electronic Dance Music
 
I gave up with OLE as it's too nasty to get an elegant solution working, so I replaced the code with a shell command

Code:
Public Declare Function ShellExecute Lib "shell32.dll" _
Alias "ShellExecuteA" (ByVal hWnd As Long, _
ByVal lpOperation As String, ByVal lpFile As String, _
ByVal lpParameters As String, ByVal lpDirectory As String, _
ByVal nShowCmd As Long) As Long

    Dim lngHWnd As Long
    Dim lngReturn As Long
    lngReturn = ShellExecute(lngHWnd, "print", Me.FileList, vbNullString, vbNullString, 0)

This works with my images as well as office documents.

I let the browser object for PDF / Web etc provide their own print option from right mouse click.

"In complete darkness we are all the same, it is only our knowledge and wisdom that separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"
Free Electronic Dance Music
 
Then it seems I can't get a print preview with ShellExecute

image_d2b2160b-0d4c-42da-9696-e3286b673126.png


"In complete darkness we are all the same, it is only our knowledge and wisdom that separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"
Free Electronic Dance Music
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top