利用VBA批量将docx或doc转换为txt

转自:https://skday.com/archives/418/

记事本新建文件,保存为vbs格式

文件内容为:

Dim array1(100)  (注:100表示该文件夹最多的文件数,如果文件数大于100请自行修改,代码中删除注的内容,下同)

Dim source(100)

Dim destination(100)

Set fs = CreateObject("Scripting.FileSystemObject")

Set f = fs.GetFolder("C:\Users\Desktop\test\") (注:文件位置)

Set fc = f.Files

i = 0

For Each f1 In fc

    array1(i) = f1.Name

    Ext = fs.GetExtensionName(array1(i))

    Ext = LCase(Ext)

    If Ext = "docx" Then

        source(i) = f & "\" & array1(i)

        destination(i) = Left(source(i), Len(source(i))-4) & "txt" (注:更改文件后缀名,4表示docx的字符长度,如果是doc则把4改为3)

        Set wordApp = CreateObject("Word.Application")

        Set wordDoc = wordApp.Documents.Open(source(i))

        wordDoc.SaveAs destination(i), 7

        wordDoc.Close

        Set wordDoc = Nothing

        wordApp.Quit

        Set wordApp = Nothing

    End If

    i = i + 1

Next


代码图

你可能感兴趣的:(利用VBA批量将docx或doc转换为txt)