Export several word documents appended in a single pdf file

后端 未结 1 818
别跟我提以往
别跟我提以往 2020-12-22 07:29

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

相关标签:
1条回答
  • 2020-12-22 07:45

    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
    
    0 讨论(0)
提交回复
热议问题