1

I have to replace a header with my new header value and footer needs to be removed.

Input:

Header
Value1||Value2|Value3|Value4
Value7|Value3||Value1|Value1
Value1|Value9|Value1||Value1
Value1||Value1|Value1|Value1
Value1||Value1|Value1|Value6
Footer

I need like below:

NewHeader
Value1||Value2|Value3|Value4
Value7|Value3||Value1|Value1
Value1|Value9|Value1||Value1
Value1||Value1|Value1|Value1
Value1||Value1|Value1|Value6

The way I am trying is:

Set oFso = CreateObject("Scripting.FileSystemObject")
Set oFile = oFso.OpenTextFile(filePath, 1, True)
strContents = Split(oFile.ReadAll, vbCrLf)
For i=0 To UBound(strContents)
   strContents(0) 'I get header and replace with my new header
Next

but strContents(0) returns entire value from the text file. How this can be handled?

Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
J_Coder
  • 707
  • 5
  • 14
  • 32

1 Answers1

0

Try this code.Hope you will get your result.

filePath="C:\Users\admin\Desktop\Qtpfile.txt"
strModifytest=""
Set oFso = CreateObject("Scripting.FileSystemObject")
Set oFile = oFso.OpenTextFile(filePath, 1, True)
strContents = Split(oFile.ReadAll, vbCrLf)
strModifytest=Replace(strContents(0), "Header","NewHeader") & vbCrLf
For i=1 To UBound(strContents)-1
 strModifytest=strModifytest & strContents(i) & vbCrLf 

Next

MsgBox strModifytest

Set oFso1 = CreateObject("Scripting.FileSystemObject")
Set oFile1 = oFso1.OpenTextFile(filePath, 2, True)
oFile1.Write(strModifytest)

Please let me know if this work.

KunduK
  • 32,888
  • 5
  • 17
  • 41