title: Rename file using FSO MoveFile and Name-As not working
body: <p>I am trying to rename a file from <code>"X"</code> to <code>"XY"</code> in the same folder. I have tried using File System Object and just the Name X as Y function, but neither is working.  I do have the Microsoft Scripting Runtime reference installed.  The code completes successfully but the file name does not change,  Please advise.</p>
  
  <pre><code>    Dim FSO As Object
  Dim srcPath As String
  Dim FromPath As String
  Dim ToPath As String
  Dim fldrName As String
  
  srcPath = "C:\"
  
  i = 1
  Set FileSysObj_1 = New FileSystemObject
  
  For Each Folder_Obj1 In FileSysObj_1.GetFolder(srcPath).SubFolders
  i = i + 1
  On Error Resume Next
  
          Set FSO = CreateObject("scripting.filesystemobject")
  
              'If the file exists in the folder then rename it
              If Dir(srcPath &amp; Folder_Obj1.Name &amp; "_Hotel.xlsx") Then
  
                  fldrName = Folder_Obj1.Name
                  FromPath = srcPath &amp; fldrName &amp; "_Hotel.xlsx"
                  ToPath = srcPath &amp; "Hotel.xlsx"
  
                  '***  Neither of the following two lines work to rename the file
                  FSO.MoveFile FromPath, ToPath
                  Name FromPath As ToPath
  
              Else
                      MsgBox "File doesn't exist."
  
              End If
  
  Next
  </code></pre>