word emailing + vba拆分word文件并转pdf
word emailing + vba拆分word文件并转pdf
Sub BatchMailMerge()
Dim DF As MailMergeDataField
Dim FN As MailMergeFieldName
Dim i As Integer
Dim NFN As String
Dim DFI
ThisDocument.Activate
If ThisDocument.MailMerge.DataSource.Name = "" Then
MsgBox "邮件合并尚未设置完毕,请完成设置后重新运行", vbCritical
Exit Sub
End If
UserForm1.ComboBox1.Clear
For Each FN In ActiveDocument.MailMerge.DataSource.FieldNames
UserForm1.ComboBox1.AddItem (FN)
Next
UserForm1.Show
For i = Int(UserForm1.TextBox1) To Int(UserForm1.TextBox2)
ActiveDocument.MailMerge.DataSource.ActiveRecord = i
For Each DFI In Split(UserForm1.Label7, "-")
NFN = NFN & ActiveDocument.MailMerge.DataSource.DataFields(Int(DFI))
Next
With ActiveDocument.MailMerge
.Destination = wdSendToNewDocument
.SuppressBlankLines = True
With .DataSource
.FirstRecord = ActiveDocument.MailMerge.DataSource.ActiveRecord
.LastRecord = ActiveDocument.MailMerge.DataSource.ActiveRecord
End With
.Execute Pause:=False
End With
ActiveDocument.SaveAs2 ThisDocument.Path & "\" & NFN & ".docx"
ActiveWindow.Close
NFN = ""
Next
End Sub
原文地址:https://blog.csdn.net/weixin_50920119/article/details/144105018
免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!