Const wdFormatText = 2
sub scan(folder)
Set FSO=WScript.CreateObject("Scripting.FileSystemObject")
Set folder=FSO.GetFolder(folder)
Set files=folder.files
for each file in files
ext=FSO.GetExtensionName(file)
ext=lcase(ext)
if ext="doc" then
Set objWord = CreateObject("Word.Application")
Set objDoc = objWord.Documents.Open(""""&file&"""")
txtfn=FSO.BuildPath(FSO.GetSpecialFolder(2),FSO.GetBaseName(file))
objDoc.SaveAs txtfn, wdFormatText
objWord.Quit
WScript.Sleep 1000
Set ReadFile = FSO.OpenTextFile(txtfn&".txt", 1)
Str=ReadFile.ReadAll
ReadFile.Close
yn=InStr(Str,"你好")
if yn<>0 then
sf=sf&file&vbcrlf
end if
end if
WScript.Sleep 1000
next
Set sfstr=FSO.CreateTextFile("d:\111.txt")
sfstr.WriteLine sf
sfstr.close
Set subfolders=folder.subfolders
for each subfolder in subfolders
scan(subfolder)
next
msgbox "含有字符串“ 你好 ”的word文档清单保存在d:\111.txt"&vbcrlf&vbcrlf&"先转了TXT,较慢,希望有人给个VBS直读DOC的。",,"WordToTxt by QQ:25926183"
Set FSO = Nothing
Set objWord = Nothing
end sub
scan("D:\111\")
Last edited by baomaboy on 2008-3-25 at 12:58 AM ]