导出附加在单个pdf文件中的多个Word文档 [英] Export several word documents appended in a single pdf file
问题描述
我在Excel工作表中有一个嵌入的MS-Word文档,名称为SalaryPaycheck
.
I have an embedded MS-Word document in an Excel Worksheet which name is SalaryPaycheck
.
MS-word文档包含几个链接到工作表"单元格的字段.
The MS-word document contains several linked fields to Worksheet cells.
我已经多次更新链接的单元格,并执行上述字段的更新.
I have update the linked cells, several times and perform updating above fields.
然后,每次字段更新时,我都需要将嵌入的MS-Word文档导出为PDF
.
Then I need perform exporting the embedded MS-Word document each time the fields have updated, as PDF
.
所以我需要所有导出的文件都附加到一个pdf文件中.
我使用以下代码:
Sub PrintIt()
Dim objWord As Word.Application
Dim objDoc As Word.Document
Dim i as Integer
ActiveSheet.OLEObjects("SalaryPaycheck").Activate
Set objWord = GetObject(, "Word.Application")
objWord.Visible = False
Set objDoc = objWord.ActiveDocument
objWord.Application.DisplayAlerts = wdAlertsNone
objWord.Application.ScreenUpdating = False
For i = 1 to 10
Range("Key").value = i
objDoc.Fields.Update
objDoc.ExportAsFixedFormat _
outputfileName:=ThisWorkbook.path & "\Results\" & "rep" & i & ".pdf" _
, exportformat:=wdExportFormatPDF _
, openafterexport:=False _
, optimizefor:=wdExportOptimizeForPrint _
, Range:=wdExportAllDocument _
, Item:=wdExportDocumentContent _
, includedocprops:=False _
, keepirm:=True _
, createbookmarks:=wdExportCreateNoBookmarks _
, docstructuretags:=True _
, bitmapmissingfonts:=True _
, useiso19005_1:=False
Next i
objWord.Quit
Set objDoc = Nothing
Set objWord = Nothing
End Sub 'Print it
如何使用与objDoc.PrintOut' whith 'Append:=True
参数相同的objDoc.SaveAs2
或objDoc.ExportAsFixedFormat
(如上所示)?
How can using objDoc.SaveAs2
or objDoc.ExportAsFixedFormat
(shown above) same as objDoc.PrintOut' whith 'Append:=True
argument?
或者在这种情况下,如何将.PrintOut
与'Append:= True'参数一起使用(PDF),它可以安静地工作(使用OutputFileName:=path & filename
和PrintToFile:=True
)
Or How can using .PrintOut
with 'Append:=True' argument in this case (PDF) which working quietly (using OutputFileName:=path & filename
and PrintToFile:=True
)
推荐答案
As said in the other question, just append the documents in word
Sub PrintIt()
Dim objWord As Word.Application
Dim objDocTotal As Word.Document
Dim objDoc As Word.Document
Dim i As Integer
Dim strOutfile As String
Dim rg As Word.Range
ActiveSheet.OLEObjects("SalaryPaycheck").Activate
Set objWord = GetObject(, "Word.Application")
objWord.Visible = True
Set objDoc = objWord.ActiveDocument
Set objDocTotal = Documents.Add
objWord.Application.DisplayAlerts = wdAlertsNone
objWord.Application.ScreenUpdating = True
For i = 1 To 10
Range("Key").Value = i
With objDoc
.Fields.Update
.Content.Copy
End With
Set rg = objDocTotal.Content
With rg
.Collapse Direction:=wdCollapseEnd
If i > 1 Then .InsertBreak wdPageBreak
.PasteAndFormat wdFormatOriginalFormatting
End With
Next i
strOutfile = "<Path>\Salary.pdf"
objDocTotal.ExportAsFixedFormat outputfileName:= _
strOutfile, exportformat:=wdExportFormatPDF, _
openafterexport:=False, optimizefor:=wdExportOptimizeForPrint, Range:= _
wdExportAllDocument, From:=1, To:=1, Item:=wdExportDocumentContent
objDocTotal.Close False
objWord.Quit
Set objDoc = Nothing
Set objWord = Nothing
End Sub
这篇关于导出附加在单个pdf文件中的多个Word文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!