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
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