0

我想将 Word 文档的每一页保存为文本文件。我使用以下代码执行此操作:

   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(对不起我的英语)

4

1 回答 1

1

我找到了我的问题的答案:

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

解决方案是将“Encoding:=msoEncodingUTF8”部分添加到 saveAs 方法中!

弗罗约

于 2012-08-01T12:34:23.817 回答