Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Art Art is offline
external usenet poster
 
Posts: 587
Default 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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 276
Default 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



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default 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


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default 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

  #5   Report Post  
Posted to microsoft.public.excel.programming
Art Art is offline
external usenet poster
 
Posts: 587
Default 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



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 703
Default 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 -


  #7   Report Post  
Posted to microsoft.public.excel.programming
Art Art is offline
external usenet poster
 
Posts: 587
Default 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 -



  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,718
Default 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 -
|
|

  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default 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


  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default 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





  #11   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 103
Default 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

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
close msgbox Dan Excel Programming 4 July 30th 07 07:40 PM
Msgbox Close Button jnf40 Excel Programming 1 September 20th 06 05:45 PM
Close msgbox ? Buddy Lee Excel Programming 3 November 22nd 05 04:14 PM
Novice - MsgBox Yes/No - Continue if Yes, Close if No Beetlejuice Excel Discussion (Misc queries) 6 August 29th 05 09:48 PM
Close a MsgBox Taffy[_2_] Excel Programming 6 October 4th 04 09:39 PM


All times are GMT +1. The time now is 07:05 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"