Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Replace a string in a word document with another string
#5
Solved: 11 Years, 4 Months ago
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
*********************************************************************
Reply


Messages In This Thread
RE: Replace a string in a word document with another string - by rekha.naik - 09-30-2010, 05:18 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Split function in string nidhishnair 13 64,604 07-07-2020, 03:47 PM
Last Post: helmzshelmz
  String Array Declaration Bhuvana 0 1,013 01-07-2020, 12:59 PM
Last Post: Bhuvana
  How to remove the spaces from a string Anand 7 29,450 08-12-2019, 04:47 PM
Last Post: sreekanthP
  String Manipulation engr.awaiszafar@gmail.com 0 1,518 10-11-2018, 11:44 AM
Last Post: engr.awaiszafar@gmail.com
  Split a string with multiple delimiters in VBScript nandha 2 8,588 02-10-2018, 06:44 PM
Last Post: nandha

Forum Jump:


Users browsing this thread: 1 Guest(s)