Duplicate Files in Different Folder

Howdy1

Board Regular
Joined
Aug 13, 2008
Messages
50
Hello,

I am trying to find a way to duplicate the files that I need to create each day in different folder. For example, I have 2 files located in the following path:

1) X:\Price Files\CME\Price_Upload 2022-05-18.xls
2) X:\Price Files\ICE\CL_Price_Upload 2022-05-18.xls

I need to make a duplicate file for each file and then rename it to the following name in the same path:
1) X:\Price Files\CME\Price_Upload 2022-05-19.xls
2) X:\Price Files\ICE\CL_Price_Upload 2022-05-19.xls

Currently, I have to manually go to the file and click on the file and then make a copy and then rename it. I tried to run the macro from Excel to try to record the steps in a Excel workbook but it didn't seem to record. I don't know what I did wrong.. Any help is greatly appreciated!

Thank you a lot!!!
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Hello!

If you need the new file names with today date, try this:
VBA Code:
Sub RenameFiles1()
Dim i%, arrFiles(), FolderName$, FileName$, FileDate, NewFileDate
Application.ScreenUpdating = False

    FolderName = "C:\YOUR\PATH\" 'amend to real path to files, don't remember the final backslash
   
    With Application.FileDialog(msoFileDialogFilePicker)
        If .Show = 0 Then Exit Sub
        ReDim arrFiles(1 To .SelectedItems.Count)
            For i = 1 To .SelectedItems.Count
                arrFiles(i) = .SelectedItems(i)
            Next i
    End With

For i = 1 To UBound(arrFiles)
        Workbooks.Open arrFiles(i)
        FileName = Split(ActiveWorkbook.Name)(0) 'get file name without date
        ActiveWorkbook.SaveCopyAs FolderName & FileName & " " & Format(Now, "YYYY-MM-DD") & ".xls" 'save copy of file with today date
        ActiveWorkbook.Close 0 'close file without save
    Next i
   
End Sub

If you need the new file names with date in the old ones plus 1 day, use another code:
VBA Code:
Sub RenameFiles2()
Dim i%, arrFiles(), FolderName$, FileName$, FileDate, NewFileDate
Dim dFileDate, sNewFileDate
Application.ScreenUpdating = False

    FolderName = "C:\YOUR\PATH\" 'amend to real path to files, don't remember the final backslash
   
    With Application.FileDialog(msoFileDialogFilePicker)
        If .Show = 0 Then Exit Sub
        ReDim arrFiles(1 To .SelectedItems.Count)
            For i = 1 To .SelectedItems.Count
                arrFiles(i) = .SelectedItems(i)
            Next i
    End With

    For i = 1 To UBound(arrFiles)
        Workbooks.Open arrFiles(i)
            FileName = Split(ActiveWorkbook.Name)(0)
           
            FileDate = Split(ActiveWorkbook.Name)(1)
            FileDate = Left(FileDate, InStrRev(FileDate, ".") - 1)
            dFileDate = CDate(FileDate)

            NewFileDate = DateAdd("y", 1, dFileDate)
            sNewFileDate = CStr(NewFileDate)
           
            ActiveWorkbook.SaveCopyAs FolderName & FileName & " " & Format(sNewFileDate, "YYYY-MM-DD") & ".xls"
            ActiveWorkbook.Close 0
    Next i
   
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,026
Messages
6,122,738
Members
449,094
Latest member
dsharae57

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