Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Workbook_BeforeClose(Cancel As Boolean) - Cancel won't work | Setting up and Configuration of Excel | |||
changing vbOKCancel button title | Excel Discussion (Misc queries) | |||
Exiting Sub when Selecting Cancel on vbOKCancel | Excel Discussion (Misc queries) | |||
Can't get Cancel to work in message box | Excel Discussion (Misc queries) | |||
cancel input | Excel Discussion (Misc queries) |