wordに特定の文字がふくまれているかチェックするWSHマクロ
"検索する文字"を自分の検索したい文字に変えて
以下をWordCheck.vbsと名前をつけて保存し、チェックしたいWord文書をWordCheck.vbsのアイコンの上にドラッグします。
Option Explicit Const searchWord = "検索する文字" Const wdReplaceNone = 0 Dim objWord, objDoc, objSelection, Cnt dim errflg errflg = 0 Set objWord = CreateObject("Word.Application") objWord.Visible = True Set objDoc = objWord.Documents.Open(Wscript.Arguments(0)) Set objSelection = objWord.Selection With objSelection.Find .Text = searchWord ' .Font.Borders(1).LineStyle _ ' = objWord.Options.DefaultBorderLineStyle .Forward = True .MatchByte = False Cnt = 0 Do While True If .Execute(, , , , , , , , , , wdReplaceNone) Then Cnt = Cnt + 1 Else Exit Do End If Loop if Cnt > 0 then Wscript.Echo .Text & " : " & Cnt errflg=1 end if End With Const wdHeaderFooterPrimary = 1 if instr(objSelection.Sections(1).Footers(wdHeaderFooterPrimary).Range.Text,searchWord)>0 then Wscript.Echo "ヘッダー・フッターに含まれています " & objSelection.Sections(1).Footers(wdHeaderFooterPrimary).Range.Text errflg = 1 end if if errflg = 0 then Wscript.Echo "OKです " & searchWord & "は見つかりません" end if