Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Replace a string in a word document with another string
#3
Solved: 10 Years, 9 Months, 2 Weeks ago
Hi,

Thanks for your response. Below is what I have tried doing.But it is not working. I'm very new to QTP. If you can help me correct it, it would be good.

The below code is not working. It is not replacing the word "QTP" with "Mercury". Opening the file for Writing (Set first_file = FS.GetFile(Doc1Path).OpenAsTextstream(ForWriting,0)) is clearing the worddoc. So I'm stuck.

***********************************************************************************
Code:
Dim Doc1Path
const ForReading = 1

Doc1Path = "D:\QTP Practice\QTP.docx"

Public Function ReplaceWord(Doc1Path)
  Set FS = CreateObject("Scripting.FileSystemObject")
  Set first_file = FS.GetFile(Doc1Path).OpenAsTextstream(ForReading,0)

  Do while first_file.AtEndOfStream =False
       str1=first_file.Read(1000)
       Replace str1,"QTP","Mercury"

Loop

  first_file.Close()
End Function

ReplaceWord(Doc1Path)
***********************************************************************************
Reply


Messages In This Thread
RE: Replace a string in a word document with another string - by rekha.naik - 09-19-2010, 11:50 PM

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

Forum Jump:


Users browsing this thread: 1 Guest(s)