Windows平台使用技巧_doc和docx转txt

Windows平台使用技巧_doc和docx转txt


方法出自此网址

步骤

  1. 新建一个word文件,打开
  2. 创建宏:点开视图;宏;录制宏;停止录制
  3. 替换宏:点开视图;宏;查看宏;选中刚才新建的宏;编辑;用以下代码替换自动生成的代码,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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值