Merge many Word docs into one (for printing as a batch)

M

Mike

The root of my question is this:
I have a number of Word documents that I want to print from Access, but as
ONE print job, so that the user is ensured that other people's print jobs
don't become intermingled.

My attempted solution:
Set rs = ...
do until rs.eof
Set wdApp = CreateObject("Word.Application")
Set doc = wdApp.Documents.Open(CStr(rs!DocPath))
wdApp.ActiveDocument.PrintOut PrintToFile:=True, Append:=True,
OutputFileName:="C:\test.doc" '(C:\test.doc exists)
rs.movenext
loop

I've tried a number of different things with the PrintOut method, but
nothing has worked so far - including not receiving an error, but nothing
actually happening to the Output file. Ideally, I'd like to print all the
documents to one file but not have to actually open the source documents.

Any suggestions? Thank in advance!
 
A

alborg

Hi Mike:

Why not simply append all the documents first before sending them to the
printer? You can do something like-

Sub Macro1()

Documents.Add DocumentType:=wdNewBlankDocument
ChangeFileOpenDirectory "C:\My Documents\"
Selection.InsertFile FileName:="AGREEMENT OF LEAVE AND
LICENCE.doc"

Selection.InsertFile FileName:="elite.doc"

ActiveDocument.SaveAs FileName:="backup.doc"

ActiveDocument.PrintOut

End Sub

Would this work?

Cheers,
Al
 
M

Mike

Thanks for the response.

I tried what you suggested, but when the files were appended to the new
blank document, the formatting of the original files were not kept intact. I
need to be able to print each Word doc exactly as they would print
individually, but print them as one print job so other users print jobs don't
intermingle.
 
A

alborg

Hi Mike:

I have an applet that you can download (URL-
http://www.box.net/shared/static/w0juje9kwg.mdb) that will scoop out all the
files in a specified Windows folder, and list them in a listbox. Conceivably,
you can do this and as the list is being made, print out each file. The code
would look something like this:

Dim wrdApp As Object
Dim wrdDoc As String
Set wrdApp = CreateObject("Word.Application")
xx = "*.*"
DoCmd.RunSQL "DELETE WordDocuments.* FROM WordDocuments;"
On Error Resume Next
With Application.FileSearch
.NewSearch
.LookIn = Forms![Handouts]![Text44]
' text44 is a textfield on the form or just define the folder
directly"C:\program files\Handouts"
.FileName = xx
.SearchSubFolders = False
End With
With Application.FileSearch
Set rst = dbs.OpenRecordset("WordDocuments", dbOpenDynaset)
If .Execute() > 0 Then '(.Execute(msoSortByFileName,
msoSortOrderDescending) <> 0) Then
For i = 1 To .FoundFiles.Count
rst.AddNew
rst![Link] = .FoundFiles(i)
rst![DocName] = Dir(rst![Link]) '.FileName
rst![PathDate] = FileDateTime(rst![Link]) '.LastModified
rst.UPDATE
Set wrdDoc = wrdApp.Documents.Open(rst![DocName])
wrdDoc.PrintOut
wrdDoc.Close
Next i
Else
MsgBox "There were no files found."
'MsgBox "There were " & .FoundFiles.Count & " file(s) found."
End If
End With

Play with it and see if it works for you...

Cheers,
Al
 
M

Mike

Thanks again for the response.

What you suggested is pretty much what I tried in the beginning. The
problem is that it creates a seperate print job for each document. I need
all X# of documents to be printed as *one* job so that other users print jobs
don't get intermingled.

Is there an API that allows multiple print events to queue into one print
job, instructing the printer to keep all pages from all docs in the job
together?

Thanks!

alborg said:
Hi Mike:

I have an applet that you can download (URL-
http://www.box.net/shared/static/w0juje9kwg.mdb) that will scoop out all the
files in a specified Windows folder, and list them in a listbox. Conceivably,
you can do this and as the list is being made, print out each file. The code
would look something like this:

Dim wrdApp As Object
Dim wrdDoc As String
Set wrdApp = CreateObject("Word.Application")
xx = "*.*"
DoCmd.RunSQL "DELETE WordDocuments.* FROM WordDocuments;"
On Error Resume Next
With Application.FileSearch
.NewSearch
.LookIn = Forms![Handouts]![Text44]
' text44 is a textfield on the form or just define the folder
directly"C:\program files\Handouts"
.FileName = xx
.SearchSubFolders = False
End With
With Application.FileSearch
Set rst = dbs.OpenRecordset("WordDocuments", dbOpenDynaset)
If .Execute() > 0 Then '(.Execute(msoSortByFileName,
msoSortOrderDescending) <> 0) Then
For i = 1 To .FoundFiles.Count
rst.AddNew
rst![Link] = .FoundFiles(i)
rst![DocName] = Dir(rst![Link]) '.FileName
rst![PathDate] = FileDateTime(rst![Link]) '.LastModified
rst.UPDATE
Set wrdDoc = wrdApp.Documents.Open(rst![DocName])
wrdDoc.PrintOut
wrdDoc.Close
Next i
Else
MsgBox "There were no files found."
'MsgBox "There were " & .FoundFiles.Count & " file(s) found."
End If
End With

Play with it and see if it works for you...

Cheers,
Al


Mike said:
Thanks for the response.

I tried what you suggested, but when the files were appended to the new
blank document, the formatting of the original files were not kept intact. I
need to be able to print each Word doc exactly as they would print
individually, but print them as one print job so other users print jobs don't
intermingle.
 

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