使用 MS Word 2010 我希望 Mailmerge 使用宏运行,将每条记录保存为单独的文件,以 PDF 格式使用其中一个字段作为文件名。这将为我节省大量时间。
我遇到的问题是格式完全丢失了,就好像它只是复制文本并将其粘贴到新文档中一样。有什么办法可以保护格式,因为没有它它是徒劳的......
提前致谢。
Sub splitter()
Dim i As Integer
Dim Source As Document
Dim Target As Document
Dim Letter As Range
Dim oField As Field
Dim FileNum As String
Set Source = ActiveDocument
ActiveDocument.MailMerge.DataSource.ActiveRecord = wdLastRecord
For i = 1 To ActiveDocument.MailMerge.DataSource.ActiveRecord
ActiveDocument.MailMerge.DataSource.ActiveRecord = i
Set Letter = Source.Range
For Each oField In Letter.Fields
If oField.Type = wdFieldMergeField Then
If InStr(oField.Code.Text, "INV_ID") > 0 Then
FileNum = oField.Result
End If
End If
Next oField
Set Target = Documents.Add
Target.Range = Letter
Target.SaveAs2 "C:\BACS\INVOICING\INVOICES\Word Export\" & FileNum, 17
Target.Close
Next i
End Sub