我已将文档设置为自动提取邮件合并的数据源。
从那里,我想将每个页面保存为它自己的文档,并将文件名设置为邮件合并值之一。
现在我进行邮件合并,然后转到“完成和合并”,然后转到“编辑单个文档”,然后运行全局(普通)宏以在中断时保存每个页面,但它保存为 Page1、Page2 等。
我想消除这一步,只需要打开文档,通过单击是从源中提取数据,然后从那里运行宏并将每个邮件合并保存为它自己的文档。
如果可以在邮件合并完成后自动运行宏并且不必打开宏窗口来启动宏,则可以加分。
这是脚本。我想消除必须“完成并合并”“编辑单个文档。
Sub Separate_NEO_Letters()
'Used to set criteria for moving through the document by section.
Application.Browser.Target = wdBrowseSection
'A mailmerge document ends with a section break next page.
'Subtracting one from the section count stop error message.
For i = 1 To ((ActiveDocument.Sections.Count) - 1)
'Select and copy the section text to the clipboard
ActiveDocument.Bookmarks("\Section").Range.Copy
'Create a new document to paste text from clipboard.
Documents.Add
Selection.Paste
'Removes the break that is copied at the end of the section, if any.
Selection.MoveUp Unit:=wdLine, Count:=1, Extend:=wdExtend
Selection.Delete Unit:=wdCharacter, Count:=1
ChangeFileOpenDirectory "S:\IT\NEO\Automation\Generated Letters"
DocNum = DocNum + 1
ActiveDocument.SaveAs FileName:="Page" & DocNum & ".doc"
ActiveDocument.Close
'Move the selection to the next section in the document
Application.Browser.Next
Next i
ActiveDocument.Close savechanges:=wdDoNotSaveChanges
End Sub