class module

rinku261

New Member
Joined
Apr 25, 2011
Messages
10
Hi There

Is there any way I want each time when I close any of the workbooks it pops up a msg and if I select yes it allows me to close me the file. If I choose no, then it keeps the file open. It should be something like the built-int message that asks if I want to save an unsaved workbook, but I want this to work even if the workbook is in a saved state. <?XML:NAMESPACE PREFIX = O /><O:P></O:P>

I think it has to go in the Personal Macro Workbook since I want it to work with every workbook opened on my machine. I’ve heard it requires something called a class module, but how do I do that in a personal macro workbook?

<O:P></O:P>
I know its tricky, but I believe in you people. Please help.<O:P></O:P>
cheers
Rinku <O:P></O:P>
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Create a blank Excel File, add the following to the ThisWorkbook module

Code:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
If MsgBox("Do you want to save", vbYesNo + vbQuestion) = vbYes Then Me.Save
End Sub

Save the file as Book.xlt in the XLSTART folder.
 
Upvote 0
Hi There

Thanks for the code ...............I saved the code into a wrkbook and saved the workbook with the name u suggested into xlstart folder ....................But the problem is the massage appears only when i am closing the Entire Excel...Not when i am closing workbook.....


I mean the c0de is working only when i am pressing Alt F4(Close excel) not when i am pressing Alt F C (Close the excel file)


Thanks

Regards
Rinku
 
Upvote 0

Forum statistics

Threads
1,224,600
Messages
6,179,836
Members
452,947
Latest member
Gerry_F

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