首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用vba将Word文档的每一页保存为txt文件(utf-8)

使用vba将Word文档的每一页保存为txt文件(utf-8)
EN

Stack Overflow用户
提问于 2012-07-31 16:46:40
回答 1查看 1.4K关注 0票数 0

我要将Word文档的每一页另存为文本文件。我用下面的代码来做这件事:

代码语言:javascript
复制
   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 (对不起,我的英语)

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-08-01 20:34:24

我找到了我问题的答案:

代码语言:javascript
复制
nDoc.SaveAs Encoding:=msoEncodingUTF8, FileFormat:=wdFormatUnicodeText, fileName:=Praefix & Format(i, "0"), AddToRecentFiles:=False

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

弗罗约

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11736327

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档