Add Today's Date to Copied File

RichJW

Board Regular
Joined
Jul 7, 2015
Messages
94
Hi all,

I have the below macro, which takes a copy of a file and places it in another location.

I’d like to edit the macro to add the date the report is run to the end of the filename saved in the destination folder. So, the name would become “Dashboard Workbook 0.31 2020-06-11.xlsm”, but “Dashboard Workbook 0.31 2020-06-18.xlsm” when I run it next week.

Sub CopyFile()

'Declare Variables

Dim FSO

Dim sFile As String

Dim sSFolder As String

Dim sDFolder As String


'File Name

sFile = "Dashboard Workbook 0.31.xlsm"


'Source

sSFolder = "C:\MyFolder\OneDrive\MI\"


'Destination

sDFolder = " C:\MyFolder\OneDrive\MI\Reports"


'Create Object

Set FSO = CreateObject("Scripting.FileSystemObject")


'Check If File Is Located in the Source Folder

If Not FSO.FileExists(sSFolder & sFile) Then

MsgBox "Specified File Not Found", vbInformation, "Not Found"


'Copy If the Same File is Not Located in the Destination Folder

ElseIf Not FSO.FileExists(sDFolder & sFile) Then

FSO.CopyFile (sSFolder & sFile), sDFolder, True

MsgBox "Specified File Copied Successfully", vbInformation, "Done"

Else

MsgBox "Specified File Already Exists In The Destination Folder", vbExclamation, "File Already Exists"

End If


End Sub


Any help appreciated.

Rich
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result

Forum statistics

Threads
1,215,692
Messages
6,126,228
Members
449,303
Latest member
grantrob

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