DisplayAlerts = False Not Working

UWMmakow

New Member
Joined
Feb 25, 2014
Messages
30
I have one macro (macro1) that calls a different macro (macro2). At the end of macro2 a MsgBox displays, which I want to suppress so macro1 can continue. Macro2 is used separately in other cases and so changing it isn't an option.

DisplayAlerts = False seems to be the code I want, but in testing it just doesn't work. So then I tested it with a barebones simple macro (i.e. turn DisplayAlerts off then call a sub that simply displays a MsgBox) and still the msg appears.

When stepping through the macro the tooltip always displays true for DisplayAlerts even immediately after DisplayAlerts = False has passed.

What's the catch here?
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
Try

Application.DisplayAlerts = False.

Note, this won't suppress message boxes created by the code..Because a message box isn't considered an 'Alert'
 
Upvote 0
Ah, I'm sorry I was using Application.DisplayAlerts.

And OK, that would explain it then. Chalk up one more reason I hate the MSDN reference- it specifically says alerts and messages.

Do you know of any way to accomplish what I'm trying to do?
 
Upvote 0
Msgbox cannot be avoided through display alerts. You can have a flag declared in general and then use it in your macro1.. something like the below code...

Code:
Dim msgFlag As Boolean 'General declaration - top of module




Sub macro1()
'
'Various codes running


msgFlag = False
Call macro2


End Sub




Sub macro2()
'
'


If msgFlag = True Then
    MsgBox "Display Meassage" 'doesnt display message if flag is set to TRUE
End If


End Sub
 
Upvote 0
This is the only way I can think to suppress messgage boxes..

Code:
Public sprss As Boolean
Sub macro1()
sprss = True
macro2
sprss = False
End Sub

Sub macro2()
If sprss = False Then
    MsgBox "hey"
End If
End Sub

But you would have to add the IF to each message box in macro2
 
Upvote 0
@vds1 The macros are in different modules unfortunately. I might just have to duplicate the code of macro2 in macro1.
 
Upvote 0
@vds1 The macros are in different modules unfortunately. I might just have to duplicate the code of macro2 in macro1.

Then declare the flag as public as shown in Jon code for sprss variable.. No need to duplicate...
 
Upvote 0
Works for me with the 2 macros in seperate modules.

Only put the Public declaration in 1 module though, either one should work.
 
Upvote 0
Ahh alright, great. Didn't know variables could be accessed across modules... I thought that was part of the point of different modules to be honest! Thanks for the insight guys.
 
Upvote 0
Glad to help, thanks for the feedback.

I don't claim to know what the intended purpose of seperate modules was, I didn't write the program.
But in my opinion, it's purpose is really just for organization to the writer's benefit.
Code that does work of type A goes in module 1
Code that does work of type B goes in module 2
etc.

Plus, I believe there is actually a limit to how much code can actually exist in one module.
So that dictates the need for multiple modules as well.
 
Upvote 0

Forum statistics

Threads
1,214,987
Messages
6,122,614
Members
449,090
Latest member
vivek chauhan

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