I have an embedded MS-Word document in an Excel Worksheet which name is SalaryPaycheck
.
The MS-word document contains several linked fields to Worksheet cells.
I have update the linked cells, several times and perform updating above fields.
Then I need perform exporting the embedded MS-Word document each time the fields have updated, as PDF
.
So I need all exported files are appending in a single pdf file.
I using below code:
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
How can using objDoc.SaveAs2
or objDoc.ExportAsFixedFormat
(shown above) same as objDoc.PrintOut' whith 'Append:=True
argument?
Or How can using .PrintOut
with 'Append:=True' argument in this case (PDF) which working quietly (using OutputFileName:=path & filename
and PrintToFile:=True
)