Macro to move file

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Is there a way to use a macro in a workbook to move a file from one folder to
another folder by copying it? I tried to record a macro to do it but nothing
shows up in the VB editor.

Thanks
Dave
 
Hi Dave

Try the following?

Sub SaveCopy()
ChDir "C:\Documents and Settings\{Enter new Directory name here}"
ActiveWorkbook.SaveAs Filename:= _
"C:\Documents and Settings\{Enter new directory and file name here},
FileFormat:=xlNormal, Password:="", WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False
End Sub

This is the result of running Macro Record, but you can adapt it to suit
your needs.
 
Yes there is- how do you want to handle the files? For instance, do
you want to save the original file in the original location, and make a
copy of the file to the new folder? Or do you want to skip right to
the Save As to the new folder, and delete the file from the original
location?

It's easily done, and for the most part can be accomplished by
recording the macro. Why the macro didn't show up in the editor is
troublesome but most likely easily overcome.
 
Actually one of the easier things to do.

Sub movefile()
OldName = "C:\oldfoldername\1065.xls"
NewName = "C:\newfoldername\1065.xls"
Name OldName As NewName
End Sub
 
Dave - I want to do exactly what you have outlined here. I want to do the
save as and delete the file from the original location. I used record macro
and the save-as worked just fine. The delete file is the part I am having
trouble with. All I could think to do was a file-open and then delete the
file there. It didn't work. It just gave me the ChDir and leaves the
original file there. What do you suggest? Pam
 
Pam,

Dim myFName As String
myFName = ActiveWorkbook.Fullname 'or use some other workbook object that points to the file

'Do your SaveAs, then use

Kill myFName


HTH,
Bernie
MS Excel MVP
 
Back
Top