title: Opening Text file, in Vba, getting Error 1004
body: <p>I have a system generated file with extensions 0001,0002 and so on. These files are editable in notepad as textfile. Below VBA Code was working but suddenly it is giving </p>
  
  <blockquote>
    <p>"error 1004 - Unable to get the replace property of the
    worksheetfunction class".</p>
  </blockquote>
  
  <p>I wrote the below code to read the file, Find &amp; remove WHT and add spaces at a specific position from where WHT was found. Code was working fine but getting this error. </p>
  
  <pre><code>Sub RemoveWHTaddspaces() 
  Dim Textfile as integer
  Dim Filepath as String
  Dim FileContent as String
  Dim Check1 as integer
  Dim Check2 as Integer
  
  Filepath = Application.Getopenfilename()
  
  Textfile=Freefile
  Open FilePath For Input as Textfile
  Filecontent = Input(LOF(Textfile), Textfile)
  Close Textfile
  
  Do
  Check1=Instr(Filecontent, "WHT ")
  Filecontent=Application.worksheetfunction.Replace(Filecontent,Check1,4,"")
  
  Filecontent=Application.worksheetfunction.Replace(Filecontent,Check1+38,25,"                   
        ")
  Check1=Instr(Filecontent, "WHT ")
  Loop while Check1&gt;0
  Textfile = Freefile
  Open Filepath For Output as Textfile
  Print #Textfile, Filecontent
  Close Textfile
  Msgbox ("Done")
  Reset
  
  End Sub
  </code></pre>