title: Rename files in folder vba
body: <p>I have code to find a filename from column A and rename files as in column B in a source folder and then copy to a new folder. </p>
  
  <p>The code is as below.</p>
  
  <pre><code>Sub Rename_Files()
      Dim SourcePath, DestPath, Fname, NewFName
      SourcePath = "C:\Invoices\"
      DestPath = "C:\Invoices\Renamed\"
      For i = 1 To 100
          Fname = Range("A" &amp; i).Value
          NewFName = Range("B" &amp; i).Value
          If Not Dir(SourcePath &amp; Fname, vbDirectory) = vbNullString Then
              FileCopy SourcePath &amp; Fname, DestPath &amp; NewFName
          Else
              MsgBox (Fname &amp; " Not Exists in Folder")
          End If
      Next i
  End Sub
  </code></pre>
  
  <p>The problem is that The filenames in the source directory are long like <code>'INVOICEDUMP_OFND_4294819_ABC Corp.pdf'</code> and hundreds of like this. </p>
  
  <p>I want to find the file containing 4294819 (from column A) in the name and then replace the name with only <code>'INV 4294819.pdf'</code> (as mentioned in column B).</p>
  
  <p>Thanks</p>