title: Excel VBA - movefile syntax
body: <p>Please help with the code for copying files one by one to the destination folder. I tried with "for Each loop but it is copying all the files at once to the destination folder. I am new to to vba and would be helpful if someone could crack the code for me. thanks in advance. here's the code i have managed to come up with. </p>
  
  <p>I am getting run time error 53, File not found,e highlighting the below syntax.</p>
  
  <pre><code>FSO.movefile Source:="C:\Users\wazeer.ahamed\Documents\Outlookemails_Macro\" &amp; Fname, Destination:="C:\Users\wazeer.ahamed\Documents\TcktIDfolder\" &amp; Fname
  
  Sub Example1()
  
  'Extracting file names Dim objFSO As Object Dim objFolder As Object Dim newobjFile As Object    
  Dim lastID As Long Dim myRRange As Range Dim Maxvalue As Integer    
  Dim sFolder As String Dim dFolder As String
  
  
  Sub Example1()
  
  'Extracting file names
  Dim FSO
  Dim objFolder As Object
  Dim newobjFile As Object
  Dim FromDir As String
  Dim ToDir As String    
  
  Dim lastID As Long
  Dim myRRange As Range
  Dim Maxvalue As Integer    
  Dim Fname As String                    
  
  FromDir = "C:\Users\wazeer.ahamed\Documents\Outlookemails_Macro\"
  ToDir = "C:\Users\wazeer.ahamed\Documents\TcktIDfolder\"    
  Fname = Dir(FromDir)
  
  If Len(FromDir) = 0 Then
      MsgBox "No files"
      Exit Sub
  End If    
  
  Set myRange = Worksheets("Sheet1").Range("C:C")    
  Maxvalue = Application.WorksheetFunction.Max(myRange)    
  lastID = Maxvalue
  
  'finding the next availabe row    
  erow = Worksheets("Sheet1").Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
  
  'Extracting file names
  
  'Create an instance of the FileSystemObject
  Set FSO = CreateObject("Scripting.FileSystemObject")
  'Get the folder object
  Set objFolder = FSO.GetFolder("C:\Users\wazeer.ahamed\Documents\Outlookemails_Macro")
  
  'loops through each file in the directory and prints their names and path        
  For Each newobjFile In objFolder.Files
  
       'print file name       
      Cells(erow, 1) = Fname    
  
      'print file path
      Cells(erow, 2) = newobjFile.Path
  
      'PrintUniqueID
      Cells(erow, 3) = lastID + 1
  
      FSO.movefile Source:="C:\Users\wazeer.ahamed\Documents\Outlookemails_Macro\" &amp; Fname, Destination:="C:\Users\wazeer.ahamed\Documents\TcktIDfolder\" &amp; Fname     
      Cells(erow, 5) = "file succesfully copied"                   
  Next newobjFile        
  
  Set FSO = Nothing
  Set newobjFile = Nothing
  Set objFolder = Nothing             
  
  End Sub    
  </code></pre>