How to print off multiple word documents

Ajz1971

New member
Local time
Today, 17:55
Joined
Oct 4, 2016
Messages
8
Hi All,

I have a query that gives me a list of Linked Word.Doc Files (C:/Policies/Policy1.Doc…. C:/Policies/Policy2.Doc etc…) what I would like to do is be able to print off all documents automatically using VBA code that I can attach to the on click of a button…Is this possible?

The query is named 'Staff Query'... The column of linked files is 'Field2'

Big thanks for any reply in advance
 
You could do that with Word Automation with code something like that below which can also be found in the attached database

Code:
Private Sub PrintAll_Click()

Dim rs As DAO.Recordset
Dim apWord As Word.Application
Dim doc As Word.Document
Set apWord = CreateObject("Word.application")
Set rs = CurrentDb.OpenRecordset("Staff Query")
Do While Not rs.EOF
   Set doc = apWord.Documents.Open(CStr(rs!Field2))
   doc.PrintOut
   doc.Close
    rs.MoveNext
Loop
rs.Close
apWord.Quit
Set rs = Nothing
Set doc = Nothing
Set apWord = Nothing

End Sub

This code requires the Microsoft Word Object Library (Tools, Refererence) and also needs error handling. I suggest your error handler close the word application (apWord.Quit) for those case where necessary or you could end up with open word processes on your system.
 

Attachments

Hi Steve,

Thanks for your help...worked a charm!!

have a great day ;)
 

Users who are viewing this thread

Back
Top Bottom