ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Msgbox Close with vba (https://www.excelbanter.com/excel-programming/420290-msgbox-close-vba.html)

Art

Msgbox Close with vba
 
Hello:

I have a code that triggers a msgbox to open and ask the user yes or no.
However, there is certain times that the msgbox triggers but I don't need it.
How can I put in the code to close the msgbox. Please understand the the code
that triggers the msgbox is not in the same sub as the code that I want to
cancel the msgbox.

Thanks.

Art

Corey

Msgbox Close with vba
 
Can you not adapt the code that triggers the msgbox with the
'Application.Displayalerts=FALSE' statement to not show when it is not
required.

Perhaps an IF or Case section of code ?

Corey....
"art" wrote in message
...
Hello:

I have a code that triggers a msgbox to open and ask the user yes or no.
However, there is certain times that the msgbox triggers but I don't need
it.
How can I put in the code to close the msgbox. Please understand the the
code
that triggers the msgbox is not in the same sub as the code that I want to
cancel the msgbox.

Thanks.

Art




Rick Rothstein

Msgbox Close with vba
 
Why do you have subroutines triggering the MessageBox when it is not needed?
What is it about your set up that would dictate the MessageBox should be
dismissed? Why can't you incorporate the logic that dictates no MessageBox
into the subroutines that trigger it?

--
Rick (MVP - Excel)


"art" wrote in message
...
Hello:

I have a code that triggers a msgbox to open and ask the user yes or no.
However, there is certain times that the msgbox triggers but I don't need
it.
How can I put in the code to close the msgbox. Please understand the the
code
that triggers the msgbox is not in the same sub as the code that I want to
cancel the msgbox.

Thanks.

Art



JLGWhiz

Msgbox Close with vba
 
Put an If...Then statement in to only fire the message box when it is needed.

If this condition is met Then
'activate the message box
Else
'ignore this and go on with the code
End If

"art" wrote:

Hello:

I have a code that triggers a msgbox to open and ask the user yes or no.
However, there is certain times that the msgbox triggers but I don't need it.
How can I put in the code to close the msgbox. Please understand the the code
that triggers the msgbox is not in the same sub as the code that I want to
cancel the msgbox.

Thanks.

Art


Art

Msgbox Close with vba
 
You all guys are great, but nobody answered my question. I'll explain why I
need it. The code that triggers the msgbox is "beforePrint" event. Now the
msgbox is also triggered when Print Preview is pressed. So I have a activex
command button that opens the print preview. So I want the msgbox not to open
when the printpreview is pressed. Any ideas?

Code BeforePrint:

If Worksheets("Order Form").Range("C3") = "You have not selected a customer
yet" Then
msg = "You have not yet selected a customer."
msg = msg & vbNewLine
msg = msg & "Are you sure you want to print?"
Ans = MsgBox(msg, vbYesNo + vbQuestion + vbDefaultButton2, "Print
Order")
If Ans = vbNo Then
Cancel = True
End If
End If
End Sub

Please help.


"JLGWhiz" wrote:

Put an If...Then statement in to only fire the message box when it is needed.

If this condition is met Then
'activate the message box
Else
'ignore this and go on with the code
End If

"art" wrote:

Hello:

I have a code that triggers a msgbox to open and ask the user yes or no.
However, there is certain times that the msgbox triggers but I don't need it.
How can I put in the code to close the msgbox. Please understand the the code
that triggers the msgbox is not in the same sub as the code that I want to
cancel the msgbox.

Thanks.

Art


Per Jessen[_2_]

Msgbox Close with vba
 
Hi

With that information given, add this line before the line that opens
Print Preview:

Application.EnableEvents=false

Just remember to set it = true before end sub.

Hopes it helps

Regards,
Per

On 20 Nov., 05:37, art wrote:
You all guys are great, but nobody answered my question. I'll explain why I
need it. The code that triggers the msgbox is "beforePrint" event. Now the
msgbox is also triggered when Print Preview is pressed. So I have a activex
command button that opens the print preview. So I want the msgbox not to open
when the printpreview is pressed. Any ideas?

Code BeforePrint:

If Worksheets("Order Form").Range("C3") = "You have not selected a customer
yet" Then
* * * * msg = "You have not yet selected a customer."
* * * * msg = msg & vbNewLine
* * * * msg = msg & "Are you sure you want to print?"
* * * * Ans = MsgBox(msg, vbYesNo + vbQuestion + vbDefaultButton2, "Print
Order")
* * * * If Ans = vbNo Then
* * * * * * Cancel = True
* * * * * * End If
* * * * End If
End Sub

Please help.



"JLGWhiz" wrote:
Put an If...Then statement in to only fire the message box when it is needed.


If this condition is met Then
* *'activate the message box
Else
* *'ignore this and go on with the code
End If


"art" wrote:


Hello:


I have a code that triggers a msgbox to open and ask the user yes or no.
However, there is certain times that the msgbox triggers but I don't need it.
How can I put in the code to close the msgbox. Please understand the the code
that triggers the msgbox is not in the same sub as the code that I want to
cancel the msgbox.


Thanks.


Art- Skjul tekst i anførselstegn -


- Vis tekst i anførselstegn -



Art

Msgbox Close with vba
 
I tried that already, it still pops up the msgbox.

"Per Jessen" wrote:

Hi

With that information given, add this line before the line that opens
Print Preview:

Application.EnableEvents=false

Just remember to set it = true before end sub.

Hopes it helps

Regards,
Per

On 20 Nov., 05:37, art wrote:
You all guys are great, but nobody answered my question. I'll explain why I
need it. The code that triggers the msgbox is "beforePrint" event. Now the
msgbox is also triggered when Print Preview is pressed. So I have a activex
command button that opens the print preview. So I want the msgbox not to open
when the printpreview is pressed. Any ideas?

Code BeforePrint:

If Worksheets("Order Form").Range("C3") = "You have not selected a customer
yet" Then
msg = "You have not yet selected a customer."
msg = msg & vbNewLine
msg = msg & "Are you sure you want to print?"
Ans = MsgBox(msg, vbYesNo + vbQuestion + vbDefaultButton2, "Print
Order")
If Ans = vbNo Then
Cancel = True
End If
End If
End Sub

Please help.



"JLGWhiz" wrote:
Put an If...Then statement in to only fire the message box when it is needed.


If this condition is met Then
'activate the message box
Else
'ignore this and go on with the code
End If


"art" wrote:


Hello:


I have a code that triggers a msgbox to open and ask the user yes or no.
However, there is certain times that the msgbox triggers but I don't need it.
How can I put in the code to close the msgbox. Please understand the the code
that triggers the msgbox is not in the same sub as the code that I want to
cancel the msgbox.


Thanks.


Art- Skjul tekst i anførselstegn -


- Vis tekst i anførselstegn -




Rick Rothstein

Msgbox Close with vba
 
Another possibility is to create a global "flag" variable and use it to
control whether the MessageBox is displayed or not. A way to implement
something like this would be to insert a Module (Insert/Module from the VB
editor), Dim a Boolean variable in it and then set the variable in those
subroutines/event procedures that you didn't want to trigger the MessageBox
and test for that set variable in the subroutine/event procedures that
contained the code to display the MessageBox. For example, in the Module
that you Insert, put this...

Public HideMsgBox As Boolean

In a subroutine that you didn't want to trigger the MessageBox, put this at
the top of the code...

HideMsgBox = True

And in the subroutine/event procedure that displays the MessageBox, encase
the MsgBox command inside an If..Then block like this...

If Not HideMsgBox Then
'
' Put your MessageBox(es) here
'
End If

--
Rick (MVP - Excel)


"art" wrote in message
...
You all guys are great, but nobody answered my question. I'll explain why
I
need it. The code that triggers the msgbox is "beforePrint" event. Now the
msgbox is also triggered when Print Preview is pressed. So I have a
activex
command button that opens the print preview. So I want the msgbox not to
open
when the printpreview is pressed. Any ideas?

Code BeforePrint:

If Worksheets("Order Form").Range("C3") = "You have not selected a
customer
yet" Then
msg = "You have not yet selected a customer."
msg = msg & vbNewLine
msg = msg & "Are you sure you want to print?"
Ans = MsgBox(msg, vbYesNo + vbQuestion + vbDefaultButton2, "Print
Order")
If Ans = vbNo Then
Cancel = True
End If
End If
End Sub

Please help.


"JLGWhiz" wrote:

Put an If...Then statement in to only fire the message box when it is
needed.

If this condition is met Then
'activate the message box
Else
'ignore this and go on with the code
End If

"art" wrote:

Hello:

I have a code that triggers a msgbox to open and ask the user yes or
no.
However, there is certain times that the msgbox triggers but I don't
need it.
How can I put in the code to close the msgbox. Please understand the
the code
that triggers the msgbox is not in the same sub as the code that I want
to
cancel the msgbox.

Thanks.

Art



Rick Rothstein

Msgbox Close with vba
 
I forgot one thing... inside the If...Then block, as the last statement, you
have to reset the global "flag" variable. So, the code for the
MessageBox(es) should have been this...

If Not HideMsgBox Then
'
' Put your MessageBox(es) here
'
HideMsgBox = False
End If

If you don't do this, the "flag" will remain set and the MessageBox(es) will
not be displayed again even when you wanted them to be.

--
Rick (MVP - Excel)


"Rick Rothstein" wrote in message
...
Another possibility is to create a global "flag" variable and use it to
control whether the MessageBox is displayed or not. A way to implement
something like this would be to insert a Module (Insert/Module from the VB
editor), Dim a Boolean variable in it and then set the variable in those
subroutines/event procedures that you didn't want to trigger the
MessageBox and test for that set variable in the subroutine/event
procedures that contained the code to display the MessageBox. For example,
in the Module that you Insert, put this...

Public HideMsgBox As Boolean

In a subroutine that you didn't want to trigger the MessageBox, put this
at the top of the code...

HideMsgBox = True

And in the subroutine/event procedure that displays the MessageBox, encase
the MsgBox command inside an If..Then block like this...

If Not HideMsgBox Then
'
' Put your MessageBox(es) here
'
End If

--
Rick (MVP - Excel)


"art" wrote in message
...
You all guys are great, but nobody answered my question. I'll explain why
I
need it. The code that triggers the msgbox is "beforePrint" event. Now
the
msgbox is also triggered when Print Preview is pressed. So I have a
activex
command button that opens the print preview. So I want the msgbox not to
open
when the printpreview is pressed. Any ideas?

Code BeforePrint:

If Worksheets("Order Form").Range("C3") = "You have not selected a
customer
yet" Then
msg = "You have not yet selected a customer."
msg = msg & vbNewLine
msg = msg & "Are you sure you want to print?"
Ans = MsgBox(msg, vbYesNo + vbQuestion + vbDefaultButton2, "Print
Order")
If Ans = vbNo Then
Cancel = True
End If
End If
End Sub

Please help.


"JLGWhiz" wrote:

Put an If...Then statement in to only fire the message box when it is
needed.

If this condition is met Then
'activate the message box
Else
'ignore this and go on with the code
End If

"art" wrote:

Hello:

I have a code that triggers a msgbox to open and ask the user yes or
no.
However, there is certain times that the msgbox triggers but I don't
need it.
How can I put in the code to close the msgbox. Please understand the
the code
that triggers the msgbox is not in the same sub as the code that I
want to
cancel the msgbox.

Thanks.

Art




Jim Rech

Msgbox Close with vba
 
When the user uses File, Print the before print event runs before the dialog
appears. So there is no way to know at that point whether the user will
pick Print or Print Preview.

If you have your own "Print" and "Print Preview" buttons running macros
you'd add your msgbox to the former only. But you'd still have to disable
all built-in ways to print to insure the user used your buttons.

--
Jim
"art" wrote in message
...
|I tried that already, it still pops up the msgbox.
|
| "Per Jessen" wrote:
|
| Hi
|
| With that information given, add this line before the line that opens
| Print Preview:
|
| Application.EnableEvents=false
|
| Just remember to set it = true before end sub.
|
| Hopes it helps
|
| Regards,
| Per
|
| On 20 Nov., 05:37, art wrote:
| You all guys are great, but nobody answered my question. I'll explain
why I
| need it. The code that triggers the msgbox is "beforePrint" event. Now
the
| msgbox is also triggered when Print Preview is pressed. So I have a
activex
| command button that opens the print preview. So I want the msgbox not
to open
| when the printpreview is pressed. Any ideas?
|
| Code BeforePrint:
|
| If Worksheets("Order Form").Range("C3") = "You have not selected a
customer
| yet" Then
| msg = "You have not yet selected a customer."
| msg = msg & vbNewLine
| msg = msg & "Are you sure you want to print?"
| Ans = MsgBox(msg, vbYesNo + vbQuestion + vbDefaultButton2,
"Print
| Order")
| If Ans = vbNo Then
| Cancel = True
| End If
| End If
| End Sub
|
| Please help.
|
|
|
| "JLGWhiz" wrote:
| Put an If...Then statement in to only fire the message box when it
is needed.
|
| If this condition is met Then
| 'activate the message box
| Else
| 'ignore this and go on with the code
| End If
|
| "art" wrote:
|
| Hello:
|
| I have a code that triggers a msgbox to open and ask the user yes
or no.
| However, there is certain times that the msgbox triggers but I
don't need it.
| How can I put in the code to close the msgbox. Please understand
the the code
| that triggers the msgbox is not in the same sub as the code that I
want to
| cancel the msgbox.
|
| Thanks.
|
| Art- Skjul tekst i anførselstegn -
|
| - Vis tekst i anførselstegn -
|
|


Arun

Msgbox Close with vba
 
Hi Avi,

I understand that you have created a msg box from VBA coding and now you
want to remove that msg box..

To remove the msg box, please open the document in which you have created
that msg box now, press ALT + F11 to enter in VBA module, now on the left
hand panel, you would have three options?

1. Sheet1
2. Sheet2
3. Sheet3

Select the sheet1 and right click and then select view code, now you will
see the vba coding, then where you will see the coding of that msg.. Please
delete that one and then click on save..

Then check, has that msg box disappear or not..?

Regards,
Arun Sharma

"art" wrote:

Hello:

I have a code that triggers a msgbox to open and ask the user yes or no.
However, there is certain times that the msgbox triggers but I don't need it.
How can I put in the code to close the msgbox. Please understand the the code
that triggers the msgbox is not in the same sub as the code that I want to
cancel the msgbox.

Thanks.

Art



All times are GMT +1. The time now is 08:43 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com