printing a word doc invisible - but how??

G

Gina

Hi all,
I try to print out a word document from within access vba so that it it
printed in the background when I set word document to visible:=False

this is the function where the error occurs:
________________________

Public Function PrintBill() As Boolean
Dim printedOK As Boolean

---> getting an automation error because of wrong syntax
Set wdApp = GetObject(Word.Application)

Set DC = GetObject(Word.ActiveDocument)
--->

wdApp.ActiveWindow.PrintOut DC, Range:=wdPrintAllDocument, Item:= _
wdPrintDocumentContent, Copies:=2, Pages:="",
PageType:=wdPrintAllPages, _
Collate:=False

wdApp.ActiveDocument.Close
Set DC = Nothing
Set wdApp = Nothing

PrintBill = True

End Function
__________________________

I set the word application visible so I have to go to word and press the
print button manually.

Any help most welcome as I don't have a clou as to what the syntax might be

Thanks,
Gina
 
J

Jezebel

When you use GetObject, you need to put quotes around the class -- it's a
literal.

Set wdApp = GetObject("Word.Application")
Set DC = wdApp.ActiveDocument

If Word is invisible, there is no ActiveWindow. But you don't need it. Just
print the document --

DC.PrintOut
 
G

Gina

Hi Jezebel.

Tried it before and tried it right now like

Public Sub PrintIt()
Set DC = GetObject(Word.ActiveDocument)
* DC.PrintOut(Copies:=2)
End Sub

* I got an error and now I changed it to
DC.PrintOut Copies:=2

and it works fine

Thanks a lot ....
Gina
 

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