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

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
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,224,824
Messages
6,181,186
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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