Call a Word Document to Print from Within Excel VBA

I have a lengthy Excel VBA script that works quite well. I have recently added to it the VBA code to send certain worksheets by email to selected individuals via Outlook from inside Excel VBA. Now, I want to add code that will call six separate one-page Word documents (already written and saved to disk as six .docx files) and print 1 copy of each of these six single-page Word document files at the end of the Excel VBA script, just before the script terminates and Excel closes. I've never called a Word document to print from within Excel with VBA, but, like with Outlook, I know it can be done.

Do any of the experts have a code snippet or sub that I could try within my Excel VBA script that would do this?

Thanks!

Glenn
Glenn StearnsAnalystAsked:
Who is Participating?
 
Rgonzo1971Commented:
then try
C:\John.docx, C:\mike.docx, C:\james.docx.
Dim objWord as Object
Dim objDoc as Object
Set objWord = CreateObject("Word.Application")
objWord.Visible = False
For Each Item in Array("C:\John.docx", "C:\mike.docx", "C:\james.docx")
    Set objDoc = objWord.Documents.Open(Item)
    objDoc.PrintOut
    objDoc.Close
Next
objWord.Quit

Open in new window

0
 
Rgonzo1971Commented:
Hi,

pls try
Dim objWord as Object
Dim objDoc as Object
Set objWord = CreateObject("Word.Application")
objWord.Visible = False
Set objDoc = objWord.Documents.Open("C:\Test\SomeDocument.docx")
objDoc.PrintOut
objDoc.Close
objWord.Quit

Open in new window

Regards
0
 
Glenn StearnsAnalystAuthor Commented:
Thanks, Rgonzo...I will try it.
Where do I deal with documents two through six? Do I just repeat lines 5, 6, and 7 for the other five documents, or do I string them out after the .Open ("  ") in line 5 somehow? Not quite sure how to write the code to do this.

Thanks!

Glenn
0
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

 
Rgonzo1971Commented:
How are they declared?
0
 
Rgonzo1971Commented:
Are they in a range? in an array?
0
 
Glenn StearnsAnalystAuthor Commented:
Rgonzo...

Not sure what you mean by declared. They are just single-page Word .docx files, like C:\John.docx, C:\mike.docx, C:\james.docx.  I suppose I could make one document that is 6 pages, but I'd rather keep them separate and name them separate in the code.

Glenn
0
 
Glenn StearnsAnalystAuthor Commented:
OK, that looks logical. I'll try that and see how it works, then let you know.

Thanks for responding!

Glenn
0
 
Glenn StearnsAnalystAuthor Commented:
Rgonzo...

Worked perfectly - just like I needed it to do for this application.

Many thanks!

Glenn
0
 
Glenn StearnsAnalystAuthor Commented:
Thanks again for your help. Most appreciated!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.