09-30-2010, 05:18 PM
I tried below pasted code and it did not replace the string.
*********************************************************************
*********************************************************************
*********************************************************************
Code:
strsearch = "QTP"
Set obj_word = CreateObject("Word.Application")
Set obj_doc = obj_word.documents.Open("D:\QTP Practice\QTP.docx")
For p=1 to obj_doc.Paragraphs.count
startrange = obj_doc.Paragraphs(p).Range.Start
endrange=obj_doc.Paragraphs(p).Range.End
Set text_range = obj_doc.Range(startrange,endrange)
text_String = text_range.Text
strlength = Len(text_String) - 1
text_String = Left(text_String, strlength )
If InStr(1, text_String, strsearch) > 0 Then
pos = InStr(1, text_String, strsearch)
msgbox pos
Replace text_String,strsearch,"Mercury"
End If
Next
obj_doc.close
obj_word.Quit
Set obj_doc = Nothing
Set obj_word = Nothing