『楼 主』:
doc2txt 批量转换
除转换doc外,还支持rtf、html转换
ON ERROR RESUME NEXT
Set fsObject = CreateObject ("Scripting.FileSystemObject")
myDocDir=wscript.arguments(0)
if myDocDir="" then msgbox "请把要转换的文件夹拖到该图标上",,"提示" : wscript.quit
If Not (fsObject.FolderExists(myDocDir)) Then
MsgBox myDocDir & "源文件夹不存在,程序终止。", vbCritical, "错误"
Wscript.Quit
End If
If InStrRev(myDocDir, "\") < Len(myDocDir) Then
myDocDir = myDocDir & "\"
End If
Set DocFilesDir = fsObject.Getfolder(myDocDir)
Set myDocFiles = DocFilesDir.Files
Set myObject = Wscript.CreateObject("Word.Application")
n = 0
For Each DocFile In myDocFiles
hz=LCase(Right(DocFile.Name,3))
If hz = "doc" or hz="rtf" or hz="tml" or hz="htm" Then
TextFileName =myDocDir & Left(DocFile.Name,InStrRev (DocFile.Name, ".")) & "txt"
myObject.Documents.Open DocFile.Path,,,,,,,,,,,False
myObject.Documents(DocFile.Path).Activate
myObject.ActiveDocument.SaveAs TextFileName, 2
myObject.ActiveDocument.Close
n = n + 1
End If
Next
If n > 0 Then
MsgBox n & "个文件成功转换!"
Else
MsgBox "转换失败!"
End If
myObject.Quit
Set myObject = Nothing
|