Copying files

charlee63

Board Regular
Joined
Jan 7, 2010
Messages
146
Trying to copy files from one location to another.
Sample
c:\Indept Ad\01-02-11 Meat Merchandiser\01-02-11 Meat Merchandise.xls
Moving to
C:\2011 Temp\
Also need to change the file Name to 2011-01-02_East_Meat_Merchandise.xls

Multi folders Date changes in incumets of 7
Need to do to current Date.
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Take a look at this link it might help.

A simple sample of code to copy a workbook to another location is shown below

http://www.rondebruin.nl/folder.htm

<font face=Courier New><SPAN style="color:#00007F">Sub</SPAN> copyfiles()<br><SPAN style="color:#00007F">Dim</SPAN> srcWk <SPAN style="color:#007F00">'The original</SPAN><br><SPAN style="color:#00007F">Dim</SPAN> cpyWk <SPAN style="color:#007F00">'Copy to new location</SPAN><br>srcWk = "M:\Excel Files\Hide.xls"<br>cpyWk = "M:\Excel Files New\hide.xls"<br>FileCopy srcWk, cpyWk <SPAN style="color:#007F00">'Using the FileCopy command</SPAN><br><br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN></FONT>
 
Upvote 0
If you have trouble with the code for handling the dates, you could try (something like) this:-
Code:
[FONT=Fixedsys]Option Explicit[/FONT]
[FONT=Fixedsys][/FONT] 
[FONT=Fixedsys]Sub CopyDatedFile()[/FONT]
[FONT=Fixedsys][/FONT] 
[FONT=Fixedsys]  Dim TodaysDate As String
  Dim SourceFile As String
  
  Dim NextWeeksDate As String
  Dim NextWeeksYear As String
  Dim TargetFile As String
  
  TodaysDate = Format(Now(), "dd-mm-yy")
  SourceFile = "C:\Indept Ad\" & TodaysDate & " Meat Merchandiser\" & TodaysDate & " Meat Merchandise.xls"
  
  NextWeeksDate = Format(Now() + 7, "yyyy-mm-dd")
  NextWeeksYear = Format(Now() + 7, "yyyy")
  TargetFile = "C:\" & NextWeeksYear & " Temp\" & NextWeeksDate & "_East_Meat_Merchandise.xls"
  
  FileCopy SourceFile, TargetFile
  [/FONT]
[FONT=Fixedsys]End Sub[/FONT]
There's no checking in this code, so you may wish to:-
  • check the source file exists before trying to copy it
  • check that the target folder exists before trying to copy the source file into it
  • check the target file doesn't exist before overwriting it
  • check that the target file exists after the copy operation
 
Upvote 0

Forum statistics

Threads
1,224,597
Messages
6,179,808
Members
452,944
Latest member
2558216095

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top