Printing a Word Doc

B

Brian Matlack

Hi!
What type of code would I use to print a Word document by clicking a
button or drawn object in an Excel worksheet? I do not want to see the
document just open the Word application print the document
("Instructions") and close the Word application. The Word document is
in the same file folder as the Excel workbook that is accessing it.

Thanks for any and all help!!
 
C

Chip Pearson

Try

Dim WordApp As Object
Dim WordDoc As Object
Set WordApp = CreateObject("Word.Application")
WordApp.Visible = False
Set WordDoc = WordApp.documents.Open(ThisWorkbook.Path &
"\Instructions.doc")
WordDoc.PrintOut
WordDoc.Close savechanges:=False
WordApp.Quit


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com



"Brian Matlack"
<[email protected]>
wrote in message
news:[email protected]...
 
A

AA2e72E

The WordDoc object is unnecessary.
WordApp.Viaible is False by default.
Need to Set WordApp = Nothing

Modified Solution:

Set WordApp = CreateObject("Word.Application")
WordApp.Open ThisWorkbook.Path & "\Instructions.doc"
WordApp.ActiveDocument.PrintOut
WordApp.ActiveDocument.Close SaveChanges:=False
WordApp.Quit
Set WordApp = Nothing

The line

WordApp.ActiveDocument.Close SaveChanges :=False

is necessary because the document may have links that get updated thereby
marking the document as changed.
 
C

Chip Pearson

WordApp.Open ThisWorkbook.Path & "\Instructions.doc"

This line won't work. You need

WordApp.Documents.Open ThisWorkbook.Path & "\Instructions.doc"
WordApp.Viaible is False by default.

Not true. In Office 2003, you'll see the application window with
the instructions.doc file open on the screen if you don't set
Visible to False.
Need to Set WordApp = Nothing

False. As long as WordApp is a local variable, it is
automatically destroyed when the procedure ends.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
 

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