Public Function VerifyTextExistenceInFile(strValueToSearch) Dim fso, strFileObj, strFile, strFileCount, wrdDoc,blnFlag,wrdApp,filesys,strPath,strFullPath,strFileName,strPara,startRange,endRange,tRange Set fso = CreateObject("Scripting.FileSystemObject") Set filesys = CreateObject("Scripting.FileSystemObject") Set strPath = filesys.GetSpecialFolder(2) 'strPath = "give the path of the file" Set strFileObj = fso.GetFolder(strPath) Set strFileCount = strFileObj.Files For Each strFile in strFileCount If strFile.type = "WWI Document" AND Instr(1,strFile.name,"rehs",1) Then strFileName = strFile.name strFullPath = strPath&"\"&strFileName Set wrdApp = CreateObject("Word.Application") ' wrdApp.DisplayAlerts = False ' wrdApp.Visible = False Set wrdDoc = wrdApp.Documents.Open(strFullPath, 0, FALSE) With wrdDoc blnFlag = False For strPara = 1 To .Paragraphs.Count startRange = .Paragraphs(strPara).Range.Start endRange = .Paragraphs(strPara).Range.End Set tRange = .Range(startRange, endRange) tRange.Find.Text = strValueToSearch tRange.Find.Execute If (tRange.Find.Found) Then blnFlag = True Exit For End If Next End With If( blnFlag = True) Then Reporter.ReportEvent micPass Else Reporter.ReportEvent micFail End If wrdApp.Quit 0 'wrdApp.Close() End If Next End Function
No comments:
Post a Comment