How to inhibit non-interactive MsgBox display

D

Denis

I'm using a VBScript to start an excel macro (opening a workbook that
automatically runs via Workbook_Open()). This macro opens another
workbook and runs a macro in it, call it macro A. Macro A generates
an informational message with a MsgBox display. Since this is running
as a non-interactive session, I need to inhibit the display of this
MsgBox. I've tried DisplayAlerts=False and that doesn't do it. How
can I inhibit this MsgBox?

Denis
 
B

Bernie Deitrick

Denis,

You need to write your code to not show it if the macro is run by other code - to do so, you could
pass it a parameter

Sub MacroA(ShowMsg As Boolean)

If ShowMsg Then Msgbox "Hello there"



Then call it like

MacroA False

HTH,
Bernie
MS Excel MVP
 
B

Bernie Deitrick

Sorry, I forgot to add that you'll need another macro to call the macro to show the msgbox

Sub CallMacroA()
MacroA True
End Sub

HTH,
Bernie
MS Excel MVP
 
D

Denis

Denis,

You need to write your code to not show it if the macro is run by other code - to do so, you could
pass it a parameter

Sub MacroA(ShowMsg As Boolean)

If ShowMsg Then Msgbox "Hello there"

Then call it like

MacroA False

HTH,
Bernie
MS Excel MVP

Is there a way for a macro to detect that it is being run in a non-
interactive session? If there is that would allow the MsgBox to be
generated conditionally. That would be a much better solution in this
case than having to create a parameter to control the conditional
generation (there are a number of messages that fall in this category)

Denis
 
B

Bernie Deitrick

You could use a global boolean, say

Public InterActiveMode As Boolean

Then use

InterActiveMode = True

when you are in you interactive mode, and

InterActiveMode = False

when you are not (How you determine that depends on how you use your project...)

Then start each MsgBox statements with

If InterActiveMode Then

along the lines of

If InterActiveMode Then MsgBox "This is my message"


HTH,
Bernie
MS Excel MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top