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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
Rgonzo1971Commented:
How are they declared?
0
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

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
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Outlook

From novice to tech pro — start learning today.