我正在尝试创建一个宏来在word 2010中进行邮件合并,然后将其拆分为不同的文档。
但是,我坚持命名文件。 我要做的是从合并文件中复制第一行,然后将其保存为字符串并使用它来创建文件名。但是此时我收到了一个权限错误。 下面是宏。任何有关此事的帮助都非常感谢
Sub Macro1()
Dim filname As String
For i = 1 To (ActiveDocument.MailMerge.DataSource.RecordCount)
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
Selection.MoveUp Unit:=wdScreen, Count:=1
Selection.EndKey Unit:=wdLine, Extend:=wdExtend
Selection.Copy
filname = Selection
ActiveDocument.SaveAs2 FileName:="C:\Users\ABC\Desktop\New folder\(Desired filename)" & filname & ".docx", FileFormat:= _
wdFormatXMLDocument, LockComments:=False, Password:="", AddToRecentFiles _
:=True
ActiveWindow.Close
ActiveDocument.MailMerge.DataSource.ActiveRecord = wdNextRecord
Next i
End Sub