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

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
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
 
Upvote 0
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
 
Upvote 0
I always made sure to do this too .. I was also surprised by the help on this property. :lol:
 
Upvote 0

Forum statistics

Threads
1,222,175
Messages
6,164,398
Members
451,890
Latest member
JamieS

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