2012-07-31 133 views
0

我想將Word文檔的每一頁保存爲文本文件。 我做這個用下面的代碼:使用vba將Word文檔的每一頁保存到txt文件(utf-8)

Sub JedeSeiteEinNeuesDokumentOhneKopfUndFusszeilen() 
    Dim oDoc As Document, nDoc As Document, oRange As Range 
    Set oDoc = ActiveDocument 
    Max = oDoc.ComputeStatistics(wdStatisticPages) 
    For i = 1 To Max 
    oDoc.Activate 
    Selection.GoTo What:=wdGoToPage, Name:=i 
    Set oRange = Selection.Bookmarks("\Page").Range 
    If Right(oRange.Text, 1) = Chr(12) Then 
     oRange.SetRange Start:=oRange.Start, End:=oRange.End - 1 
    End If 
    Set nDoc = Documents.Add(Template:=ActiveDocument.AttachedTemplate.FullName) 
    nDoc.Content.FormattedText = oRange.FormattedText 
    s = nDoc.ComputeStatistics(wdStatisticPages) 
    'Wenn eine 2. Seite mit einem einzigen leeren Absatz entstanden ist 
    If s = 2 And nDoc.Paragraphs.Last.Range.Text = Chr(13) Then 
     nDoc.Paragraphs.Last.Range.Delete 
    End If 
    nDoc.SaveAs FileFormat:=wdFormatUnicodeText, fileName:=Praefix & Format(i, "0"), AddToRecentFiles:=False 
    nDoc.Close 
    Next i 
End Sub 

但我想,txt文件是UTF-8。我該怎麼做呢?

感謝
升級Froyo (對不起,我的英語)

回答

1

我發現我的問題的答案:

nDoc.SaveAs Encoding:=msoEncodingUTF8, FileFormat:=wdFormatUnicodeText, fileName:=Praefix & Format(i, "0"), AddToRecentFiles:=False 

溶液添加部分 「編碼:= msoEncodingUTF8」 到SaveAs方法!

froyo

相關問題