将多个Word文档打印为PDF

时间:2014-03-12 18:12:55

标签: vba ms-access access-vba ms-access-2010

挑战:打印多个Word文档(最多2到10个文档)到单个PDF

可用数据:文档及其要打印的位置

使用的逻辑:遍历包含所有文档路径的查询的记录集

撞墙:无法找到最佳方法吗?

Dim WordObj As Object
Set WordObj = CreateObject("Word.Application")
Dim db As DAO.Database
Dim rs As DAO.Recordset

Set db = CurrentDb
Dim strSql As String
strSql = QryLinkstoDocs

Set rs = db.OpenRecordset(strSql, dbOpenSnapshot)
Dim fileName As String
 Do While Not rs.EOF
     fileName = rs.Fields(0) 'This field has the link to the files
     WordObj.Documents.Open filename

     'WordObj.PrintOut Background:=False 'This works for single file 

     WordObj.PrintToFile "C:\Temp.pdf", collate = True
     rs.MoveNext
Loop
WordObj.Quit
Set WordObj = Nothing

2 个答案:

答案 0 :(得分:0)

这完成了这项工作:

基本上我创建了一个新单词doc并将每个文件中的内容插入到它中,最后,将单个doc打印到PDF。

Do While Not rs.EOF     
         fName = rs.Fields(0)

        If FileExists(fName) Then
          oApp.Selection.InsertFile _
          FileName:=CStr(fName), Range:=""
          oApp.Selection.InsertBreak
        Else
          Debug.Print "The File is missing"
        End If
        rs.MoveNext
Loop
oApp.Activedocument.PrintOut Background:=False

答案 1 :(得分:-1)

我一直都很喜欢pdftk (pdf toolkit)。我没有使用它,因为他们添加了GUI并增加了功能,但是有一个非常简单的命令行界面,允许您组合,分离等PDF。您可以在Access中编写一个简单的脚本,生成要组合的文件列表,然后发送命令行代码以执行。

他们自述的一个例子:

Join in1.pdf and in2.pdf into a new PDF, out1.pdf
     pdftk in1.pdf in2.pdf cat output out1.pdf
or (using handles):
     pdftk A=in1.pdf B=in2.pdf cat A B output out1.pdf
or (using wildcards):
     pdftk *.pdf cat output combined.pdf
相关问题