我想搜索所有保存在同一文件夹中的大量word文件,在每个文档中搜索关键字。
当标识包含关键字的文档时,脚本应将文档文件名输出到文本文件报告中。
到目前为止,我已经创建了以下脚本,用于搜索指定的单词docs以设置术语。对于特定文件,此脚本显然是硬编码的,如果您可以演示如何使其全部搜索 ".doc"
文件夹中的文件很棒。它也不会创建文本文件报告。
Set objWord = CreateObject("Word.Application")
objWord.Visible = True
Set objDoc = objWord.Documents.Open("L:\STSMP00001.docx")
Set objSelection = objWord.Selection
objSelection.Find.Forward = True
objSelection.Find.MatchWildcards = True
objSelection.Find.Text = "presentation"
Do While True
objSelection.Find.Execute
If objSelection.Find.Found Then
strWord = objSelection.Text
strWord = Replace(strWord, "[[", "")
strWord = Replace(strWord, "]]", "")
Wscript.Echo strWord
Else
Exit Do
End If
Loop
Set objWord = CreateObject("Word.Application")
objWord.Visible = True
Set objDoc = objWord.Documents.Open("L:\STSMP00002.docx")
Set objSelection = objWord.Selection
objSelection.Find.Forward = True
objSelection.Find.MatchWildcards = True
objSelection.Find.Text = "presentation"
Do While True
objSelection.Find.Execute
If objSelection.Find.Found Then
strWord = objSelection.Text
strWord = Replace(strWord, "[[", "")
strWord = Replace(strWord, "]]", "")
Wscript.Echo strWord
Else
Exit Do
End If
Loop