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

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
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,215,331
Messages
6,124,311
Members
449,152
Latest member
PressEscape

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