ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Macro to move file (https://www.excelbanter.com/excel-discussion-misc-queries/51087-macro-move-file.html)

Dave

Macro to move file
 
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

Kassie

Macro to move file
 
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.

--
ve_2nd_at. Randburg, Gauteng, South Africa


"Dave" wrote:

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


Dave O

Macro to move file
 
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.


Don Guillett

Macro to move file
 
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

--
Don Guillett
SalesAid Software

"Dave" wrote in message
...
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




Pam M

Macro to move file
 
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

"Dave O" wrote:

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.



Bernie Deitrick

Macro to move file
 
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


"Pam M" wrote in message
...
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

"Dave O" wrote:

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.






All times are GMT +1. The time now is 02:18 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com