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

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.

evanmer

New Member
Joined
Apr 20, 2012
Messages
14
@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

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
85,069
Office Version
  1. 365
Platform
  1. Windows
ADVERTISEMENT
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

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
85,069
Office Version
  1. 365
Platform
  1. Windows
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,195,674
Messages
6,011,105
Members
441,582
Latest member
Topkapi

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
Top