Hi,
I have a directory containing some word documents (*.doc). I need to code a batch file which can open the doc and if the document contains the text “LOGO THREAD COLOR SHEET”, I need to create a {filename}.prn file.
Can some one help?
Thanks,
Balaji.
Thanks,
Balaji.
That’s harder to do, and would probably require the use of Word’s COM objects. Batch cannot access COM, so here’s a VBScript:
Const searchStr = "LOGO THREAD COLOR SHEET" Const wordVisible = True 'or False WScript.Quit Main Function Main On Error Resume Next Dim fso, word, f Dim doc, r Set fso = CreateObject("Scripting.FileSystemObject") Set word = CreateObject("Word.Application") word.Visible = wordVisible word.DisplayAlerts = False For Each f In fso.GetFolder(".").Files If LCase(fso.GetExtensionName(f)) = "doc" Then Set doc = word.Documents(word.Documents.Open(f.Path, False, True, False)) Set r = doc.Range r.WholeStory If r.Find.Execute(searchStr, True, False, False, False, False, True, 1) Then _ doc.PrintOut False, False, 0, GetPrnName(f), , , 0, 1, , 0, True Set r = Nothing doc.Close 0 End If Next 'f word.Quit 0 Main = Err.Number End Function Function GetPrnName(path) 'As String Dim name : name = Split(path, ".") name(UBound(name)) = "prn" GetPrnName = Join(name, ".") End Function