Saving a new version of spreadsheet to a folder using VBA

gt213

Board Regular
Joined
Jul 5, 2016
Messages
61
I have a spreadsheet with c20 sheets in it and a lot of VB code.

I want to have a macro that will save a copy of the spreadsheet (with name = value in cell B3 of sheet 1) in the folder:
G:\Indv\EQA\Rec. I'd also like to have the new version saved without the VB code in it, and as an xlsx.

Once the macro is run i want to close the new version of the spreadsheet (saved as above) and continue working in the original version. (e.g. if i were to run the macro then make some changes to the spreadsheet and click save, it would save the changes to the original version).

Hope that makes sense.
 
Last edited:

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
Sounds simple enough...

Code:
On Error Resume Next
SuccessSave = ActiveWorkbook.SaveAs Filename:= "G:\Indv\EQA\Rec"&Sheets("Sheet1").range("B3").Value&".xlsx" FileFormat:=xlWorkbookNormal ConflictResolution:=xlUserResolution AddToMru:=True
If Err.Number <> 0 Then
    On Error Goto 0
    Msgbox("Unable to save workbook")
Else
    On Error Goto 0
End If

The Conflict resolution parameter - if the file already exists, it will ask you if you want to overwrite. You can force it to overwrite with =xlLocalSessionChanges
AddtoMRU - will add to recently Used files list.

HTH
 
Last edited:
Upvote 0
Sounds simple enough...

Code:
On Error Resume Next
SuccessSave = ActiveWorkbook.SaveAs Filename:= "G:\Indv\EQA\Rec"&Sheets("Sheet1").range("B3").Value&".xlsx" FileFormat:=xlWorkbookNormal ConflictResolution:=xlUserResolution AddToMru:=True
If Err.Number <> 0 Then
    On Error Goto 0
    Msgbox("Unable to save workbook")
Else
    On Error Goto 0
End If

The Conflict resolution parameter - if the file already exists, it will ask you if you want to overwrite. You can force it to overwrite with =xlLocalSessionChanges
AddtoMRU - will add to recently Used files list.

HTH

Thanks Johnny, i came across a similar solution elsewhere but without the conflict resolution, which i like and will add in to my code.
 
Upvote 0

Forum statistics

Threads
1,223,897
Messages
6,175,270
Members
452,628
Latest member
dd2

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