Copying workbook to new folder

mrtim2232

New Member
Joined
Aug 24, 2017
Messages
48
Hi All,

I found this code online and tried to adapt it to suit my needs but i'm not having much luck. I would like to copy my test file to my weekly backup folder and include today's date in the name of the backup file when it has been copied over. Any help would be appreciated, Thanks in advance.

Sub sbCopyingAFile()
Dim FSO
Dim sFile As String
Dim sSFolder As String
Dim sDFolder As String
Dim dFile As String
dFile = sFile & Format(Date, "dd-mm-yyyy")
sFile = "test"
sSFolder = "E:"
sDFolder = "E:\weekly backup"
Set FSO = CreateObject("Scripting.FileSystemObject")
If Not FSO.FileExists(sSFolder & sFile) Then
MsgBox "Specified File Not Found", vbInformation, "Not Found"
ElseIf Not FSO.FileExists(sDFolder & sFile) Then
FSO.CopyFile (sSFolder & dFile), 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
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Try
Code:
Sub sbCopyingAFile()

    Dim FSO
    Dim sFile As String
    Dim sSFolder As String
    Dim sDFolder As String
    Dim dFile As String
    
    sFile = "test"
    dFile = sFile & Format(Date, "dd-mm-yyyy")
    sSFolder = "E:\"
    sDFolder = "E:\weekly backup\"
    Set FSO = CreateObject("Scripting.FileSystemObject")
    If Not FSO.FileExists(sSFolder & sFile & ".[COLOR=#ff0000]xlsm[/COLOR]") Then
        MsgBox "Specified File Not Found", vbInformation, "Not Found"
    ElseIf Not FSO.FileExists(sDFolder & dFile & ".[COLOR=#ff0000]xlsm[/COLOR]") Then
        FSO.CopyFile (sSFolder & sFile & ".[COLOR=#ff0000]xlsm[/COLOR]"), sDFolder & dFile & ".[COLOR=#ff0000]xlsm[/COLOR]", 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
I'm assuming that the test file is an xlsm file, if not change the extensions in red to suit
 
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,216,484
Messages
6,130,936
Members
449,608
Latest member
jacobmudombe

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