如何将word批量转化为txt-doc批量转txt宏代码

www.tzvx.com 2021-01-11生活日记人已围观

简介word文档批量转txt格式,宏代码: 步骤:打开一个word文档或者新建,点 视图-新建宏 ,在打开的代码框中,全部删除之前代码,复制下面代码黏贴进去,点击左上角保存图标,进行保存...

word文档批量转txt格式,宏代码:
步骤:打开一个word文档或者新建,点视图-新建宏,在打开的代码框中,全部删除之前代码,复制下面代码黏贴进去,点击左上角保存图标,进行保存,然后点击导航栏“运行”
浏览需要转换的文件(Ctrl+A 可全选),转换后的txt文件在原来文件夹中。

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

Tags:

热点文章