背景:我已经创建了一个Excel模板来邮寄,将字段合并到一个Word文档中,并生成5个不同的信件,这将发送给一个客户。
任务:让Word VBA代码运行自动邮件合并,并提示使用从邮件合并字段派生的文件名保存(或自动保存)到特定目录中。
即。
(唯一标识符)+首字母名称+要保存在首字母文件夹中的日期
(唯一标识符)+第二个字母的名称+保存在第二个字母文件夹中的日期
等等。
问题:我不知道如何指定目录或如何插入邮件合并字段作为文件名的一部分。
以下是我拥有的代码
Sub MailMerge()
With ActiveDocument.MailMerge
.Destination = wdSendToNewDocument
.SuppressBlankLines = True
With .DataSource
.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord
End With
.Execute Pause:=False
End With
With Dialogs(wdDialogFileSummaryInfo)
.Title = "Letter1Draft" & Format(Now(), "mmddyyyy") & ".doc"
.Execute
End With
' Then this!
With Dialogs(wdDialogFileSaveAs)
.Show
End With
End Sub发布于 2017-12-09 18:11:49
下面的代码选择目录。它不允许您插入邮件合并域作为文件名。
Sub AllSectionsToSubDoc()
Dim x As Long
Dim Sections As Long
Dim Doc As Document
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Set Doc = ActiveDocument
Sections = Doc.Sections.Count
For x = Sections - 1 To 1 Step -1
Doc.Sections(x).Range.Copy
Documents.Add
ActiveDocument.Range.Paste
ActiveDocument.SaveAs (Doc.Path & "\" & x & ".pdf")
ActiveDocument.Close False
Next x
Application.ScreenUpdating = True
Application.DisplayAlerts = True
End Subhttps://stackoverflow.com/questions/7099012
复制相似问题