title: xls to xlsx conversion using vba name statement corrupts the file
body: <p>I am trying to rename a file from <code>abcd.xls</code> to <code>xyz.xlsx</code> using the following code-</p>
  
  <pre><code>  NumOfAttachments = Range("RecCount").Value
    DestinationFolderPath = Range("destinationfolder").Value
    NewShtName = "Sheet1"
  
    If NumOfAttachments &lt;&gt; 0 Then
      For X = 0 To NumOfAttachments - 1
        OrigName = Range("Startcell").Offset(X, 1).Value
        NewName = Range("startcell").Offset(X, 2).Value
        SourceFolderPath = Range("startcell").Offset(X, 3).Value
        NewFile = DestinationFolderPath &amp; NewName
        If Dir(DestinationFolderPath &amp; OrigName) &lt;&gt; "" Then Kill DestinationFolderPath &amp; OrigName
        FileCopy SourceFolderPath &amp; OrigName, DestinationFolderPath &amp; OrigName
  
        If Dir(NewFile) &lt;&gt; "" Then Kill NewFile
        Name DestinationFolderPath &amp; OrigName As NewFile
  </code></pre>
  
  <p>After this when I try to open the file(<code>xyz.xlsx</code>) I get the following error-</p>
  
  <p><code>excel cannot open the file xyz.xlsx because the file format or file extension is not valid</code></p>