View Single Post
  #8   Report Post  
Posted to microsoft.public.excel.programming
Jim Rech Jim Rech is offline
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 -
|
|