【问题标题】:How to print a single document in pdf via Word 2007 (mail merge)如何通过 Word 2007 以 pdf 格式打印单个文档(邮件合并)
【发布时间】:2012-12-22 17:16:33
【问题描述】:

我有一个有趣的问题,但在某处找不到答案。 我需要打印大约 2000 封信,当然我会使用 Mail Merge 来完成。问题:我需要每一个都以 pdf 格式打印出来。我发现我必须在 Word 中使用 VBA 宏来获取单个字母(而不是在一个文档中获取全部字母),这已经有效。但我不知道如何自动将它们转换成 pdf。

有没有人有想法可以帮助我?我感谢您的帮助。

到目前为止我得到了什么(通过邮件合并制作单个文档):

    Sub EinzelDatei() 

    Dim actpath As String, Dateiname As String 
    Dim fs As Object 
    Dim LetzterRec As Long 


    Const path As String = "D:\Test\" 

    On Error GoTo 0 

    Application.ScreenUpdating = False 
    Application.Visible = False 

    ActiveDocument.MailMerge.DataSource.ActiveRecord = wdLastRecord 
    LetzterRec = Word.ActiveDocument.MailMerge.DataSource.ActiveRecord 

    ActiveDocument.MailMerge.DataSource.ActiveRecord = wdFirstRecord 

    With ActiveDocument.MailMerge 
        .DataSource.ActiveRecord = wdFirstRecord 
        Do 
            If .DataSource.ActiveRecord > 0 Then 
                .Destination = wdSendToNewDocument 
                .SuppressBlankLines = True 

               With .DataSource 

                    actpath = path & "\"          'Der aktuelle Pfad wird zusammengesetzt 

                    Set fs = CreateObject("Scripting.FileSystemObject") 
                    If fs.folderexists(actpath) = False Then MkDir (actpath) 'Wenn der Pfad         noch nicht existiert wird er jetzt erstellt 


                    .FirstRecord = .ActiveRecord 
                    .LastRecord = .ActiveRecord 

                Dateiname = actpath & _ 
                    .DataFields("No").Value & "-" & _ 
                    .DataFields("Surname").Value & "," & _ 
                    .DataFields("First_Name").Value & ".docx"                  'Dateiname =                 Name, Vorname.doc 
                End With 
                .Execute Pause:=False 

                ActiveDocument.SaveAs FileName:=Dateiname                   '
                ActiveDocument.Close False 
            End If 

        If .DataSource.ActiveRecord < LetzterRec Then 
             .DataSource.ActiveRecord = wdNextRecord 
          Else 
             Exit Do 
          End If 
       Loop 


    End With 


    MsgBox ("Erledigt") 
    Application.Visible = True 
    Application.ScreenUpdating = True 

    End Sub

提前谢谢你!!!

【问题讨论】:

    标签: vba pdf printing ms-word mailmerge


    【解决方案1】:

    使用

    ActiveDocument.SaveAs FileName:=Dateiname, FileFormat:=wdsaveformat.wdFormatPDF

    或许

    ActiveDocument.SaveAs2 FileName:=Dateiname, FileFormat:=wdsaveformat.wdFormatPDF

    但它只能在 Word 2007 SP2(我认为)及更高版本中工作。

    【讨论】:

    • 谢谢!我会试试看,稍后通知你(我要到周末才上班:-()!
    • 这个在这里工作正常:ActiveDocument.SaveAs FileName:=Dateiname, FileFormat:=wdsaveformat.wdFormatPDF 但正如我所说,它不适用于早期版本的 Word 2007 - PDF 格式选项是首次发布时不存在。
    【解决方案2】:

    在 Word 2007 中,导出功能可以将文件保存为 pdf:

    ActiveDocument.ExportAsFixedFormat OutputFileName:= _
            "Path to PDF", ExportFormat:= _
            wdExportFormatPDF
    

    【讨论】:

      【解决方案3】:

      有点简单,但您可以将默认打印机设置为 PDF 创建器,然后使用打印功能。在 2010 年,您在完成合并后会获得打印或编辑选项。

      【讨论】:

        猜你喜欢
        • 2023-04-09
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多