Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBScript to search out multiple different words.

Status
Not open for further replies.

ffemtoncall

Programmer
Feb 28, 2008
1
US
What I have below is the script to find a server name, when the backup completed, how many files it was, and how many bytes it was.

When I run the script I get the first server name to catch and then the script exits. I think my logic is pretty sound. Anyone shed some light?

Thank you!
Code:
Set objWord = CreateObject("Word.Application")

Set objDoc = objWord.Documents.Open("C:\temp\BEX_USDC01BK01_01406.txt")
Set objSelection = objWord.Selection

objSelection.Find.Forward = True
objSelection.Find.MatchWildcards = True

Do While True
   '==========================================================
    'Find server name
    '==========================================================
    preFind = "Backup of ""\\"
    postFind = "\C:"
    objSelection.Find.Text = preFind & "*" & postFind
    objSelection.Find.Execute
    If objSelection.Find.Found Then
        strWord = objSelection.Text
        strWord = Replace(strWord, preFind, "")
        strWord = Replace(strWord, postFind, "")
        strBody = strBody & strWord & vbCrLf
    Else
        Exit Do
    End If
    
    '==========================================================
    'Find Time Ended
    '==========================================================
    preFind = "completed on 2/7/2008 at "
    postFind = "\."
    objSelection.Find.Text = preFind & "*" & postFind
    objSelection.Find.Execute
    If objSelection.Find.Found Then
        strWord = objSelection.Text
        strWord = Replace(strWord, preFind, "")
        strWord = Replace(strWord, postFind, "")        
        strBody = strBody & strWord & vbCrLf
    Else
        Exit Do
    End If
    
    '==========================================================
    'Find # Of Files
    '==========================================================
    preFind = "Backed up "
    postFind = " files in"
    objSelection.Find.Text = preFind & "*" & postFind
    objSelection.Find.Execute
    If objSelection.Find.Found Then
        strWord = objSelection.Text
        strWord = Replace(strWord, preFind, "")
        strWord = Replace(strWord, postFind, "")        
        strBody = strBody & strWord & vbCrLf
    Else
        Exit Do
    End If    
    
    '==========================================================
    'Find Size
    '==========================================================
    preFind = "Processed "
    postFind = " bytes in"
    objSelection.Find.Text = preFind & "*" & postFind
    objSelection.Find.Execute
    If objSelection.Find.Found Then
        strWord = objSelection.Text
        strWord = Replace(strWord, preFind, "")
        strWord = Replace(strWord, postFind, "")        
        strBody = strBody & strWord & vbCrLf
    Else
        Exit Do
    End If
Loop

Wscript.Echo strBody

objDoc.close
objWord.quit
 
You should look into using regular expressions to find your text.

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top