我想使用excel vba通过将合并数据从excel文件转换为word文件来创建PDF。 邮件合并部分运行良好。但是,邮件合并后导出的PDF文件的目录已损坏。它显示超链接失败。 有人知道如何解决吗?非常感谢。
Sub MailMerge1()
Application.Calculation = xlCalculationManual
Dim wdocSource As Object
Dim strWorkbookName As String
rlrow = Worksheets("temp_E").Cells(Rows.Count, "B").End(xlUp).Row
Call SelectRow
On Error Resume Next
Set wd = GetObject(, "Word.Application")
If wd Is Nothing Then
Set wd = CreateObject("Word.Application")
End If
On Error GoTo 0
Set wdocSource = wd.Documents.Open("C:\Users\user1\Desktop\test\eng.docx")
strWorkbookName = "C:\Users\user1\Desktop" & "\" & ThisWorkbook.Name
wdocSource.MailMerge.MainDocumentType = wdFormLetters
wdocSource.Activate
wdocSource.MailMerge.OpenDataSource _
Name:=strWorkbookName, _
SQLStatement:="SELECT * FROM `temp_E$`"
With wdocSource.MailMerge
.Destination = wdSendToNewDocument
.SuppressBlankLines = True
With .DataSource
.FirstRecord = TargetRow - 1
.LastRecord = TargetRow - 1
End With
.Execute Pause:=False
End With
wd.Visible = True
wdocSource.Close SaveChanges:=False
wd.ActiveDocument.ExportAsFixedFormat OutputFileName:="C:\Users\user1\Desktop\test1.pdf", _
ExportFormat:=wdExportFormatPDF, _
OpenAfterExport:=True, _
OptimizeFor:=wdExportOptimizeForPrint, _
Range:=wdExportAllDocument, _
Item:=wdExportDocumentContent, _
IncludeDocProps:=True, KeepIRM:=True, _
CreateBookmarks:=wdExportCreateNoBookmarks, _
DocStructureTags:=True, _
BitmapMissingFonts:=True, _
UseISO19005_1:=False
Set wdocSource = Nothing
Set wd = Nothing
Application.Calculation = xlCalculationAutomatic
End Sub