Vba 从带有标题的邮件合并生成txt文件

Vba 从带有标题的邮件合并生成txt文件,vba,ms-word,Vba,Ms Word,我正在尝试进行邮件合并,并为每个条目生成一个.txt文件。.txt文件的标题应与邮件合并中的一个“我的”字段相对应(尝试使用ActiveDocument.MailMerge.fields(1))。当前我的脚本未运行,但不会产生错误 如果有人能提出建议,我们将不胜感激。谢谢 当前代码: Option Explicit Sub AllSectionsToSubDoc() Dim x As Long Dim Sections As Long

我正在尝试进行邮件合并,并为每个条目生成一个.txt文件。.txt文件的标题应与邮件合并中的一个“我的”字段相对应(尝试使用
ActiveDocument.MailMerge.fields(1))
。当前我的脚本未运行,但不会产生错误

如果有人能提出建议,我们将不胜感激。谢谢

当前代码:

Option Explicit   

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
    Call ActiveDocument.SaveAs(Doc.Path & "\" & ActiveDocument.MailMerge.Fields(1) & ".txt", wdFormatText)
    ActiveDocument.Close False
  Next x

  Application.ScreenUpdating = True
  Application.DisplayAlerts = True
End Sub
试试这个:

Call ActiveDocument.SaveAs(Doc.Path & "\" & ActiveDocument.Fields(1).Result & ".txt", wdFormatText)

或/和更改字段数量(如果需要)

Call ActiveDocument.SaveAs(Doc.Path & "\" & ActiveDocument.Sections(x).Fields(1).Result & ".txt", wdFormatText)