Save Copy As to a different folder

daren.beaney

New Member
Joined
Jun 14, 2011
Messages
16
Hi, I've got this code that allows me to create a backup copy of my workbook however I can't find any code that I can include that will save the copy to defined folder location e.g. "G:\My Documents\Temp\AMP\Archive"

I'm sure it's easy but I can't find anything that seems to work with this code structure

This is the code as it stands which saves a copy into the same folder location (AMP):

Code:
Sub SaveArchive()
Dim sFileName As String
    Dim sDateTime As String


    With ThisWorkbook
        sDateTime = " (" & Format(Now, "dd-mm-yy hhmm") & ").xlsm"
        sFileName = Application.WorksheetFunction.Substitute _
          (.FullName, ".xlsm", sDateTime)
         
        .SaveCopyAs sFileName
    End With


End Sub

Thanks in advance!
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Code:
    ThisWorkbook.SaveCopyAs "G:\My Documents\Temp\AMP\Archive\" & Replace(ThisWorkbook.Name, ".xlsm", " (" & Format(Now, "dd-mm-yy hhmm") & ").xlsm")
 
Upvote 0
Hi John, thanks for this, it worked fine when tested locally, however when I place the actual required destination, it saves it in the file location (01 Stakeholders) any idea what's preventing it saving to the Archive folder - it does exist.

Code:
Sub Archive()
ThisWorkbook.SaveCopyAs "F:\Adfact\Adelphi Modernisation\Business Change - Comms\01 Stakeholders\Archive" _
& Replace(ThisWorkbook.Name, ".xlsm", " (" & Format(Now, "dd-mm-yy hhmm") & ").xlsm")
End Sub

Thanks
Daren
 
Upvote 0
Thanks John, that worked a treat! I should have realised that based on the filename included 'Archive'.

Do you by any chance know how to include a userID into the file name based on the code I'm using?
 
Upvote 0
Call the Environ function to get the USERNAME environment variable:
Code:
Sub Archive()
ThisWorkbook.SaveCopyAs "F:\Adfact\Adelphi Modernisation\Business Change - Comms\01 Stakeholders\Archive" _
& Replace(ThisWorkbook.Name, ".xlsm", " (" & Environ("USERNAME") & Format(Now, " dd-mm-yy hhmm") & ").xlsm")
End Sub
 
Upvote 0
Call the Environ function to get the USERNAME environment variable:
Code:
Sub Archive()
ThisWorkbook.SaveCopyAs "F:\Adfact\Adelphi Modernisation\Business Change - Comms\01 Stakeholders\Archive\" _
& Replace(ThisWorkbook.Name, ".xlsm", " (" & Environ("USERNAME") & Format(Now, " dd-mm-yy hhmm") & ").xlsm")
End Sub

Thanks John, that worked perfectly!
 
Upvote 0

Forum statistics

Threads
1,223,270
Messages
6,171,102
Members
452,379
Latest member
IainTru

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