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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

printing microsoft office docs and spreadsheets 1

Status
Not open for further replies.

cochise

Technical User
Mar 27, 2001
171
US
Does anyone know how to create a button that prints a excel file or word document? Or the code I would put behind the button?
 
this is a bit cut down from what I actually use but should work:
Sub ScriptPrintButton()
Dim docpath, docname As String

Dim QtyToPrint As Integer

docpath = "\\PHARM-SVR\AJSM\ajs svr\scripts\approved\"
rem [document] is the document file name stored in a field on the form
docname = docpath & [Document]
rem [qty] is the number to print stored in a field on the form
QtyToPrint = [qty]

Set oApp = New Word.Application
oApp.Visible = False
oApp.Documents.Open Filename:=docname, ReadOnly:=True

oApp.ActivePrinter = "\\PHARM_DENISE\MRNOISY"

oApp.PrintOut Filename:=docname, Copies:=QtyToPrint

oApp.Documents.Close
oApp.Quit

Set oApp = Nothing
End Sub

you get problems with word being visible and word printing messages even if you set the app.visible to false. works better if you create a document object to print and make that invisible as well. but can't get away from word printing messages ... which are a pain if you're printing hundreds of copies like we do.
make sure to put in word in references.
hope this helps
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top