VBA to save a .XLSM file as two different names in same folder and continue code uninterrupted

jblonde002

Board Regular
Joined
Jun 10, 2014
Messages
61
Sorry for title, tried my best!

I have a workbook called DPD.xlsm. I would like it that every time a user presses "save" it overwrites a different .xlsm workbook called "Import.xlsm" that always resides in the same folder directory it also needs to then save a second time as it normally would (DPD.xlsm). This has to be with no overwrite confirmation popups.

I have next to zero experience writing VBA and have visited a lot of forums but can't see how this is possible? Thanks in advance for anyone that can help!
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
Not sure if anyone knows if this is possible or impossible? At this stage just knowing whether to give up with my hunt for the answer if someone could confirm it's impossible!
 
Upvote 0
Not sure if anyone knows if this is possible or impossible? At this stage just knowing whether to give up with my hunt for the answer if someone could confirm it's impossible!


is the second workbook just a copy of the workbook you are saving?

if so, this will do what you need.

Code:
Public isSaving As Boolean
Private Sub Workbook_AfterSave(ByVal Success As Boolean)
    If Not isSaving Then
        isSaving = True
        Application.DisplayAlerts = False
        ActiveWorkbook.SaveAs Filename:=ThisWorkbook.Path & "\example.xlsm"
        Application.DisplayAlerts = True
        isSaving = False
    End If
End Sub

Paste it into the "ThisWorkbook" code module.
 
Last edited:
Upvote 0
Thank you so much!!!

I have done a slight edit as below to save it back as DPD.xlsm but this is so helpful - I appreciate your time and wisdom lots after trying this for hours!

Code:
Public isSaving As BooleanPrivate Sub Workbook_AfterSave(ByVal Success As Boolean)
    If Not isSaving Then
        isSaving = True
        Application.DisplayAlerts = False
        ActiveWorkbook.SaveAs filename:=ThisWorkbook.Path & "\import.xlsm"
        ActiveWorkbook.SaveAs filename:=ThisWorkbook.Path & "\DPD.xlsm"
        Application.DisplayAlerts = True
        isSaving = False
    End If
End Sub
 
Upvote 0
Use SaveCopyAs instead of the first SaveAs and then you don't need the second SaveAs:
Code:
ActiveWorkbook.SaveCopyAs Filename:=ActiveWorkbook.Path & "\Import.xlsm"
 
Upvote 0
Thank you so much!!!

I have done a slight edit as below to save it back as DPD.xlsm but this is so helpful - I appreciate your time and wisdom lots after trying this for hours!

Code:
Public isSaving As BooleanPrivate Sub Workbook_AfterSave(ByVal Success As Boolean)
    If Not isSaving Then
        isSaving = True
        Application.DisplayAlerts = False
        ActiveWorkbook.SaveAs filename:=ThisWorkbook.Path & "\import.xlsm"
        ActiveWorkbook.SaveAs filename:=ThisWorkbook.Path & "\DPD.xlsm"
        Application.DisplayAlerts = True
        isSaving = False
    End If
End Sub


Happy to help. No thanks needed. Be sure to click that like button tho. :P
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,952
Messages
6,175,596
Members
452,658
Latest member
GStorm

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