workbook_activate() and DisplayAlerts problem!!

Andreysen

New Member
Joined
Jul 3, 2007
Messages
4
I don't know if I'm going crazy or if my Excel sheet is. I have the following macro in an empty workbook:

Private Sub workbook_activate()
MsgBox Application.DisplayAlerts
Application.DisplayAlerts = False
MsgBox Application.DisplayAlerts
End Sub

Pretty straight forward. Now, when I open another workbook in order to activate and deactivate the books, the following happens:
Once you jump to the new workbook and back the method engages and a box pops up saying "true". After hitting OK another box pops up saying "false". Just what I expected. When you now jump over to the other workbook and back again, the first box says "true" again and the second one "false" of course.
So jumping back and forth seems to set the Application.DisplayAlerts to true again. Can that be?
What am I missing here? I tried it on different PCs once with XL2000 once with XL2003. Same thing.
Try it out and see for yourself. Thanks for your help,
Andre

P.S.: I just realized the following:
When I type
Application.DisplayAlerts = False
and
MsgBox Application.DisplayAlerts
into the immediate window the msgbox displays "true" also... what's going on??
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.

xenou

MrExcel MVP
Joined
Mar 2, 2007
Messages
16,836
Office Version
  1. 2019
Platform
  1. Windows
Hi Andreysen.

Looks like this property applies while a macro is executing, not to the application permanently.

From the help files on displayalerts:

Remarks
The default value is True. Set this property to False if you don’t want to be disturbed by prompts and alert messages while a macro is running; any time a message requires a response, Microsoft Excel chooses the default response.

If you set this property to False, Micorosoft Excel sets this property to True when the code is finished, unless you are running cross process code.

When using the SaveAs method for workbooks to overwrite an existing file, the 'Overwrite' alert has a default of 'No', while the 'Yes' response is selected by Excel when the DisplayAlerts property is set equal to True.

HTH
 

Andreysen

New Member
Joined
Jul 3, 2007
Messages
4
Strange

Hmm, I thought I read somewhere especially to make sure to switch it back to true at the end because otherwise it'll stay that way but I guess not...
Thanks for the hint. I guess I'll have to work with something like workbook_change() or workbook_calculate().

ANDRE
 

xenou

MrExcel MVP
Joined
Mar 2, 2007
Messages
16,836
Office Version
  1. 2019
Platform
  1. Windows
I always made sure to do this too .. I was also surprised by the help on this property. :LOL:
 
Learn Excel from Bill Jelen

Understanding data is crucial, and the easiest place to start is with Microsoft Excel.

Forum statistics

Threads
1,151,566
Messages
5,765,150
Members
425,264
Latest member
Towervibe

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