2014-01-20 14 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) 

или/и при необходимости изменить количество полей.

Смежные вопросы