How to activate module my clicking x to save as new name and close

shelbsassy

New Member
Joined
Sep 4, 2009
Messages
5
Hello,
I am very new to VBA and I have a module to save a file with a static name and the current date. I want to be able to click the red x and run the module. Is there a way to do that? Currently I am using a shortcut to run the module but when I click the x I would like to activate the module to save the file with a new name.

My code is
Sub filesave()
ActiveWorkbook.SaveAs ("L:\Regulatory Reporting\LOBs\MLTSS\MLTSS Reports Deliverables\MLTSS REPORT FOLDERS\Ad Hoc\Incomplete Assessments\Reports\Incomplete Assessments 2023\SNP_MLTSS_Incomplete_Assessments_" & Format(Now(), "MMDDYYYY") & ".xlsm")
End Sub

Thank you for any help.
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
I believe you're looking for the BeforeClose event. Try putting this in 'ThisWorkbook' sheet.

VBA Code:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
ActiveWorkbook.SaveAs ("L:\Regulatory Reporting\LOBs\MLTSS\MLTSS Reports Deliverables\MLTSS REPORT FOLDERS\Ad Hoc\Incomplete Assessments\Reports\Incomplete Assessments 2023\SNP_MLTSS_Incomplete_Assessments_" & Format(Now(), "MMDDYYYY") & ".xlsm")
End Sub
 
Upvote 0
I believe you're looking for the BeforeClose event. Try putting this in 'ThisWorkbook' sheet.

VBA Code:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
ActiveWorkbook.SaveAs ("L:\Regulatory Reporting\LOBs\MLTSS\MLTSS Reports Deliverables\MLTSS REPORT FOLDERS\Ad Hoc\Incomplete Assessments\Reports\Incomplete Assessments 2023\SNP_MLTSS_Incomplete_Assessments_" & Format(Now(), "MMDDYYYY") & ".xlsm")
End Sub
That worked perfectly! THANK YOU!
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

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