Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 71
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 80
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 71
Default 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
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
Workbook_BeforeClose(Cancel As Boolean) - Cancel won't work gpmichal Setting up and Configuration of Excel 1 May 12th 09 02:33 AM
changing vbOKCancel button title Jase Excel Discussion (Misc queries) 8 August 19th 08 08:56 PM
Exiting Sub when Selecting Cancel on vbOKCancel Rob Excel Discussion (Misc queries) 6 June 1st 07 03:46 AM
Can't get Cancel to work in message box * Kenneth * Excel Discussion (Misc queries) 1 March 30th 06 08:10 PM
cancel input ME @ Home Excel Discussion (Misc queries) 1 February 22nd 06 09:49 AM


All times are GMT +1. The time now is 06:13 AM.

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

About Us

"It's about Microsoft Excel"