Wednesday, January 14, 2009

Search for a word and replace the word with a new word then save as a different file name

'Before this script executes, you need to have a "Greetings.doc" in C drive and it contains some information. In that information each line is contains a word "Good". Now my objective is to Replace the word "Good" with "Bad". And save file with new name.
################################################################

Set Word = CreateObject("Word.Application")
Word.Visible = TRUE
Set WordDoc=Word.Documents.Open ("C:\Greetings.doc")
Do
With Word.Selection.Find
.Text = "Good"
.Replacement.Text = "Bad"
.Forward = True
.wrap=1
.Format = False
.MatchWholeWord = True
End With
Word.Documents.Application.Selection.Find.Execute
If Word.Selection.Find.Found Then
Word.Selection.Range="bad"
else
Exit Do
End If
Loop
WordDoc.SaveAS "C:\BadGreetings.doc"

QTP VB Script Trainings

Check out this SlideShare Presentation:
QTP VB Script Trainings
View SlideShare presentation or Upload your own.

QTP Shortcut Keys

Check out this SlideShare Presentation:
QTP Shortcut Keys
View SlideShare presentation or Upload your own.

QTP Descriptive Programming

Check out this SlideShare Presentation: