2014-01-20 61 views
0

我正在嘗試通過郵件合併併爲每個條目生成一個.txt文件。 .txt文件的標題應該與郵件合併中的一個字段相對應(嘗試使用ActiveDocument.MailMerge.Fields(1))來獲取它)。目前,我的腳本不運行但不會產生錯誤。通過郵件合併生成txt文件標題

如果有人有任何建議,將不勝感激感謝

當前代碼:。

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 

回答

0

試試這個:

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

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

或/和如果需要更改字段的數量。