Excel Macro - Moving files

February 13, 2009 at 08:28:30
Specs: Windows XP
Dear All,

I would like to copy and paste my file(Any type) from one drive to another.

For example:

I have 10 files in c:\eliaz\Deal1 to d:\deals done using macro.

Files may be of any type such as pdf, word, excel, tif, img, outlook, etc.,

Please do the needful

Thanks & Regards,
Mohammed Eliaz
email Id: meliaz@zenta.com


See More: Excel Macro - Moving files

Report •


#1
February 13, 2009 at 16:10:47
Here are 2 methods.

This first one has the Source and Destination folders hardcoded into the macro.

Sub CopyFilesGeneric()
  sfol = "C:\Documents and Settings\User1\Desktop\My Source Folder"
  dfol = "D:\My Destination Folder"
   Set fso = CreateObject("Scripting.FileSystemObject")
         fso.CopyFile (sfol & "\*.*"), dfol
End Sub

This one accepts user input to build the Source and Destination folder names. In this example, only the final folder of the path is asked for. With modification, a larger portion of the Source and/or Destination path could be asked for.

 Sub CopyFilesWithInput()
'Get Source Folder
  Source_Folder = Application.InputBox("Enter Source Folder Name", _
                                       "Source Folder Name", Type:=2)
   If Source_Folder = "False" Then Exit Sub
'Get Destination Folder
  Destination_Folder = Application.InputBox("Enter Destination Folder Name", _
                                            "Destination Folder Name", Type:=2)
   If Destination_Folder = "False" Then Exit Sub
'Build Source and Destination Variables
    sfol = "C:\Documents and Settings\User1\Desktop\" & Source_Folder
    dfol = "D:\" & Destination_Folder
'Perform Copy
     Set fso = CreateObject("Scripting.FileSystemObject")
         fso.CopyFile (sfol & "\*.*"), dfol
End Sub



Report •
Related Solutions


Ask Question