Windows平台使用技巧_doc和docx转txt
方法出自此网址
步骤
- 新建一个word文件,打开
- 创建宏:点开视图;宏;录制宏;停止录制
- 替换宏:点开视图;宏;查看宏;选中刚才新建的宏;编辑;用以下代码替换自动生成的代码,F5运行,选择多个文件,点击确定,转后的text在同级目录下。
代码:
Sub Doc2txt()
Dim myDialog As FileDialog
Dim oFile As Variant
Dim oDoc As Document
Set myDialog = Application.FileDialog(msoFileDialogFilePicker)
With myDialog
.Filters.Clear
.Filters.Add "WORD 97-03 文档", "*.doc", 1
.AllowMultiSelect = True
If .Show <> -1 Then Exit Sub
Application.ScreenUpdating = False
For Each oFile In .SelectedItems
Set oDoc = Word.Documents.Open(FileName:=oFile, Visible:=False)
oDoc.SaveAs FileName:=Left(oFile, Len(oFile) - 3) & "txt", FileFormat:=wdFormatText
oDoc.Close
Next
Application.ScreenUpdating = True
End With
End Sub
Sub Docx2txt()
Dim myDialog As FileDialog
Dim oFile As Variant
Dim oDoc As Document
Set myDialog = Application.FileDialog(msoFileDialogFilePicker)
With myDialog
.Filters.Clear
.Filters.Add "WORD 文档", "*.docx", 1
.AllowMultiSelect = True
If .Show <> -1 Then Exit Sub
Application.ScreenUpdating = False
For Each oFile In .SelectedItems
Set oDoc = Word.Documents.Open(FileName:=oFile, Visible:=False)
oDoc.SaveAs FileName:=Left(oFile, Len(oFile) - 4) & "txt", FileFormat:=wdFormatText
oDoc.Close
Next
Application.ScreenUpdating = True
End With
End Sub