Find Text And Replace Entire Line in Notepad with New Text

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rahulwagh
    New Member
    • Feb 2013
    • 29

    Find Text And Replace Entire Line in Notepad with New Text

    Hi,

    I have a notepad and I want to find a text into notepad.
    Once I find the text in notepad then I want to replace entire line with new text.
    This I want to do using Excel VBA.

    I have written a code that searches in a file but replaces only the text which it finds but not the entire line.

    Below is my code
    Code:
    Open folderPath & "\XXXX_VARIABLE.txt" For Input As iFile2
                text = Input$(LOF(1), iFile2)
                arr = Split(text, vbNewLine)
            Close iFile2
            iFile2 = FreeFile
            Open folderPath & "\XXXX_VARIABLE.txt" For Output As iFile2
            For Each item In arr
                line = Replace(CStr(item), SrchString, ReplString, 1)
                
                Print #iFile2, line
            Next
            Close iFile2
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    This thread has been moved to the Excel forum.

    You need to look for the string you want and then print out your replacement text. You can't use the Replace function.

    Comment

    • Luuk
      Recognized Expert Top Contributor
      • Mar 2012
      • 1043

      #3
      "I have a notepad and I want to find a text into notepad."

      Better, more correct, would be:
      I have a text file in which i want to find a text

      Notepad is a program which can be used to open/edit text files.

      Comment

      Working...