How to use personal macros that will work each time any excel file closes

evanmer

New Member
Joined
Apr 20, 2012
Messages
14


I've writtenamacro in my whose purpose is to ask me, when I try to close thefile, whetheror not all tasks have been completed within that specificfile. Rather than addthis to the numerous excel files I get into each day, I'dlike to add it to mypersonal workbook. The problem I’m having is that thespecific code only workswhen I store the code in each unique file, as opposedto my personal workbook.Any recommendations on how to do this?


Code:
[COLOR=#222222][FONT=Verdana]Private Sub Workbook_BeforeClose(Cancel As Boolean) [/FONT][/COLOR]
[COLOR=#222222][FONT=Verdana]Dim ans AsVbMsgBoxResult [/FONT][/COLOR]
[COLOR=#222222][FONT=Verdana]ans =MsgBox("Are you sure you have done everything", vbYesNo + vbQuestion)[/FONT][/COLOR]
[COLOR=#222222][FONT=Verdana]If ans = vbNoThen Cancel = True[/FONT][/COLOR]
[COLOR=#222222][FONT=Verdana]End Sub[/FONT][/COLOR]
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
@Logit and @alansidman

Yes I’ve stored them properly in my personal workbook. Theissue I’m having is that the macros only work for when the user (me) commandsthem to run, as opposed to them running when certain actions happen; in my casethat’s when any excel file is closed.
 
Upvote 0
Try this in your Personalworkbook
Code:
' needs to go in ThisWorkbook module
Public WithEvents App As Application


Private Sub App_WorkbookBeforeClose(ByVal Wb As Workbook, Cancel As Boolean)
If MsgBox("Are you sure you have done everything", vbYesNo + vbQuestion) = vbNo Then Cancel = True
End Sub

Private Sub Workbook_Open()
   Set App = Application
End Sub
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,159
Members
453,021
Latest member
Justyna P

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