ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Qn: vbOKCancel -- Cancel doesn't work?? (https://www.excelbanter.com/excel-programming/308179-qn-vbokcancel-cancel-doesnt-work.html)

Michael Vaughan

Qn: vbOKCancel -- Cancel doesn't work??
 
Hello Everyone,

I have installed a print command to print a page. I also added a msgbox to
remind the person to turn on the printer. See below:

Sub PrintFP()
'
' Print Flight Plan Info Macro
' Macro recorded 8/21/2004 by Michael Vaughan
'

MsgBox "Be Sure Your Printer Is On!", vbInformation + vbOKCancel,
"Printer Alert"
Sheets("Print").Select
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
Sheets("Flight Plan").Select
Range("B4").Select

Well, the msgbox comes up ok.. but when I click on "Cancel" to NOT print..
it prints anyway??? What do I need to do to activate the cancel portion of
the OKCancel??

Thanks.. mv




mangesh_yadav[_46_]

Qn: vbOKCancel -- Cancel doesn't work??
 
You need to tell what button is pressed, a little modification to you
code does the trick

Sub PrintFP()
'
' Print Flight Plan Info Macro
' Macro recorded 8/21/2004 by Michael Vaughan
'

button_pressed = MsgBox("Be Sure Your Printer Is On!", vbInformation
vbOKCancel, "Printer Alert")

if button_pressed = 1 then ' if ok is pressed, the value is 1

Sheets("Sheet2").Select
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
Sheets("Sheet1").Select
Range("B4").Select

else

msgbox("You cancelled the print command") ' if cancel presse
value is 2

end if

End Sub

- Manges

--
Message posted from http://www.ExcelForum.com


Norman Jones

vbOKCancel -- Cancel doesn't work??
 
Hi Michael,

Try something like:

Sub PrintFP()
Dim res As Long

res = MsgBox("Be Sure Your Printer Is On!", _
vbInformation + vbOKCancel, "Printer Alert")
If res = vbCancel Then
MsgBox "You cancelled!"
Exit Sub
End If
Sheets("Print").Select
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
Sheets("Flight Plan").Select
Range("B4").Select

End Sub

---
Regards,
Norman



"Michael Vaughan" wrote in message
...
Hello Everyone,

I have installed a print command to print a page. I also added a msgbox

to
remind the person to turn on the printer. See below:

Sub PrintFP()
'
' Print Flight Plan Info Macro
' Macro recorded 8/21/2004 by Michael Vaughan
'

MsgBox "Be Sure Your Printer Is On!", vbInformation + vbOKCancel,
"Printer Alert"
Sheets("Print").Select
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
Sheets("Flight Plan").Select
Range("B4").Select

Well, the msgbox comes up ok.. but when I click on "Cancel" to NOT print..
it prints anyway??? What do I need to do to activate the cancel portion

of
the OKCancel??

Thanks.. mv






Nikos Yannacopoulos[_5_]

vbOKCancel -- Cancel doesn't work??
 
Michael,

You are using the OK/Cancel message box type, but you are not checking what
the user has clicked. Modify your code as follows:

Sub PrintFP()
'
' Print Flight Plan Info Macro
' Macro recorded 8/21/2004 by Michael Vaughan
'

vConfirm = MsgBox("Be Sure Your Printer Is On!", vbInformation +
vbOKCancel, _
"Printer Alert")
If vConfirm = vbCancel Then Exit Sub
Sheets("Print").Select
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
Sheets("Flight Plan").Select
Range("B4").Select

HTH,
Nikos

"Michael Vaughan" wrote in message
...
Hello Everyone,

I have installed a print command to print a page. I also added a msgbox

to
remind the person to turn on the printer. See below:

Sub PrintFP()
'
' Print Flight Plan Info Macro
' Macro recorded 8/21/2004 by Michael Vaughan
'

MsgBox "Be Sure Your Printer Is On!", vbInformation + vbOKCancel,
"Printer Alert"
Sheets("Print").Select
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
Sheets("Flight Plan").Select
Range("B4").Select

Well, the msgbox comes up ok.. but when I click on "Cancel" to NOT print..
it prints anyway??? What do I need to do to activate the cancel portion

of
the OKCancel??

Thanks.. mv






Michael Vaughan

vbOKCancel -- Cancel doesn't work??
 
Hi Nikos,

That is exactly what I was looking for!!! Thanks a million.
mv

"Nikos Yannacopoulos" wrote in message
...
Michael,

You are using the OK/Cancel message box type, but you are not checking

what
the user has clicked. Modify your code as follows:

Sub PrintFP()
'
' Print Flight Plan Info Macro
' Macro recorded 8/21/2004 by Michael Vaughan
'

vConfirm = MsgBox("Be Sure Your Printer Is On!", vbInformation +
vbOKCancel, _
"Printer Alert")
If vConfirm = vbCancel Then Exit Sub
Sheets("Print").Select






All times are GMT +1. The time now is 11:19 PM.

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