title: How to delete .xls files using VBA?
body: <p>I am no expert when it comes to using VBA. However, I have a task to convert thousnds of files located in folders and sub folders. I have found online the below code and my question  is: can the code be modified in a way that it can delete the old .xls files after conversion?</p>
  <pre><code>Public Sub test()
      RenameFilesInFolders &quot;M:\test\&quot;, True
      MsgBox &quot;Finished&quot;
  End Sub
  
  Public Sub RenameFilesInFolders(path As String, Optional recurse As Boolean)
      Dim fso As Object, fldr As Object
      
      If Right(path, 1) &lt;&gt; &quot;\&quot; Then
          path = path &amp; &quot;\&quot;
      End If
      
      Set fso = CreateObject(&quot;Scripting.FileSystemObject&quot;)
      Set fldr = fso.GetFolder(path)
      
      renameFiles fldr, recurse
  End Sub
  
  Private Sub renameFiles(fldr As Object, recurse As Boolean)
      Dim file As Object, subFldr As Object
      For Each file In fldr.Files
          changeFileExtension file
      Next
      If recurse And fldr.SubFolders.Count &gt; 0 Then
          For Each subFldr In fldr.SubFolders
              renameFiles subFldr, recurse
          Next
      End If
  End Sub
  
  Private Sub changeFileExtension(file As Object)
      Dim xlFile As Workbook
      Dim strCurrentFileExt As String
      Dim strNewFileExt As String
      Dim strNewName As String
  
      strCurrentFileExt = &quot;.xls&quot;
      strNewFileExt = &quot;.xlsx&quot;
      strNewName = file.Name
  
      If Right(strNewName, Len(strCurrentFileExt)) = strCurrentFileExt Then
          Set xlFile = Workbooks.Open(file.path, , True)
          strNewName = Replace(strNewName, strCurrentFileExt, strNewFileExt)
          Application.DisplayAlerts = False
          Select Case strNewFileExt
              Case &quot;.xlsx&quot;
                  xlFile.SaveAs file.ParentFolder &amp; &quot;\&quot; &amp; strNewName, XlFileFormat.xlOpenXMLWorkbook
              Case &quot;.xlsm&quot;
                  xlFile.SaveAs file.ParentFolder &amp; &quot;\&quot; &amp; strNewName, XlFileFormat.xlOpenXMLWorkbookMacroEnabled
          End Select
          xlFile.Close
          Application.DisplayAlerts = True
      End If
      
  End Sub
  </code></pre>