我希望能够将活动文件保存在 Word 2010 MailMerge 中,其文件名源自数据库字段“First_Name”和数据库字段“Last_Name”到作为硬编码子文件夹的子文件夹中。
我收到一个错误,即"requested member of the collection does not exist"
.
我知道当您尝试访问不存在的对象时会发生此错误。数据库字段是 First_Name,我也尝试了 First Name,以防代码正在搜索 First Name 的 Address Field,它已与 First_Name 的数据库字段配对。这是我尝试过的:
Sub SavingIndividuallyByCustomerName()
Dim firstname As String
Dim lastname As String
firstname = ActiveDocument.FormFields("First_Name").Result
lastname = ActiveDocument.FormFields("Last_Name").Result
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
ChangeFileOpenDirectory "C:\folder\subfolder\subsubfolder\"
ActiveDocument.SaveAs2 FileName:= _
"C:\folder\subfolder\subsubfolder\" & firstname & lastname & ".docx"
End Sub
当我用
firstname = "John"
lastname = "Doe"
我没有其他错误并且保存了活动文件。
我也尝试使用但没有成功:
Dim firstname As Field
Dim lastname As Field