Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,388
Default how do I make a routine run after the 'cancel' butten is pressed .

Basically I have a macro which contains a vbYesNoCancel message box. I need
the macro to run a sub-routine when the user clicks 'cancel'. At the moment
it just escapes out of the macro and stops. I don't seem to be able to
manipulate the vbCancel as an elseif for the user response. Is there any kind
of onCancel functionality or another way to run a sub-routine when the user
clicks cancel? Or do I have to create my own dialog box from scratch?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default how do I make a routine run after the 'cancel' butten is pressed .

Sub tester1()
Dim ans As Long
ans = MsgBox("What to do", vbYesNoCancel)
Select Case ans
Case vbYes
MsgBox "You said Yes"
Case vbNo
MsgBox "You said No"
Case vbCancel
MsgBox "You said cancel"
End Select

End Sub

Works for me.

--
Regards,
Tom Ogilvy




"Dave" wrote in message
...
Basically I have a macro which contains a vbYesNoCancel message box. I

need
the macro to run a sub-routine when the user clicks 'cancel'. At the

moment
it just escapes out of the macro and stops. I don't seem to be able to
manipulate the vbCancel as an elseif for the user response. Is there any

kind
of onCancel functionality or another way to run a sub-routine when the

user
clicks cancel? Or do I have to create my own dialog box from scratch?



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,388
Default how do I make a routine run after the 'cancel' butten is press

Thanks, I was trying if and else ifs - this seems like it should solve the
problem, much appreciated!!!!!!!!!!!!

"Tom Ogilvy" wrote:

Sub tester1()
Dim ans As Long
ans = MsgBox("What to do", vbYesNoCancel)
Select Case ans
Case vbYes
MsgBox "You said Yes"
Case vbNo
MsgBox "You said No"
Case vbCancel
MsgBox "You said cancel"
End Select

End Sub

Works for me.

--
Regards,
Tom Ogilvy




"Dave" wrote in message
...
Basically I have a macro which contains a vbYesNoCancel message box. I

need
the macro to run a sub-routine when the user clicks 'cancel'. At the

moment
it just escapes out of the macro and stops. I don't seem to be able to
manipulate the vbCancel as an elseif for the user response. Is there any

kind
of onCancel functionality or another way to run a sub-routine when the

user
clicks cancel? Or do I have to create my own dialog box from scratch?




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 212
Default how do I make a routine run after the 'cancel' butten is pressed .

Enclose the Right part after msgbox in to paranthesis and assign the
response of msgbox to a variable

e.g

Dim userResponse As String

userResponse = MsgBox ("Do you want to save changes?"
If userResponse = vbCancel Then
'code if cancel is clicked
End If

OR if you are working on all 3 possible responses then

Select Case userResponse
Case vbOK
'code if OK clicked
Case vbNO
'code if NO clicked
Case vbCancel
'code if Cancel clicked
End Select

Sharad

"Dave" wrote in message
...
Basically I have a macro which contains a vbYesNoCancel message box. I
need
the macro to run a sub-routine when the user clicks 'cancel'. At the
moment
it just escapes out of the macro and stops. I don't seem to be able to
manipulate the vbCancel as an elseif for the user response. Is there any
kind
of onCancel functionality or another way to run a sub-routine when the
user
clicks cancel? Or do I have to create my own dialog box from scratch?



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 212
Default how do I make a routine run after the 'cancel' butten is pressed .

corrections:

1. Dim userResponse As Integer
"Though String will work, this is correct type.

2. MsgBox ("Do you want to save changes?", vbYesNoCancel)

But I realize that by the time I write this corrections, you already
got other better responses from Tom and an AlphaNumeric fellow ;-)

cheers

Sharad

"Sharad Naik" wrote in message
...
Enclose the Right part after msgbox in to paranthesis and assign the
response of msgbox to a variable

e.g

Dim userResponse As String

userResponse = MsgBox ("Do you want to save changes?"
If userResponse = vbCancel Then
'code if cancel is clicked
End If

OR if you are working on all 3 possible responses then

Select Case userResponse
Case vbOK
'code if OK clicked
Case vbNO
'code if NO clicked
Case vbCancel
'code if Cancel clicked
End Select

Sharad

"Dave" wrote in message
...
Basically I have a macro which contains a vbYesNoCancel message box. I
need
the macro to run a sub-routine when the user clicks 'cancel'. At the
moment
it just escapes out of the macro and stops. I don't seem to be able to
manipulate the vbCancel as an elseif for the user response. Is there any
kind
of onCancel functionality or another way to run a sub-routine when the
user
clicks cancel? Or do I have to create my own dialog box from scratch?







  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default how do I make a routine run after the 'cancel' butten is pressed .

1. Dim userResponse As Integer

To be totally accurate, you should declare the variable as a
Long.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com



"Sharad Naik" wrote in message
...
corrections:

1. Dim userResponse As Integer
"Though String will work, this is correct type.

2. MsgBox ("Do you want to save changes?", vbYesNoCancel)

But I realize that by the time I write this corrections, you
already
got other better responses from Tom and an AlphaNumeric fellow
;-)

cheers

Sharad

"Sharad Naik" wrote in message
...
Enclose the Right part after msgbox in to paranthesis and
assign the response of msgbox to a variable

e.g

Dim userResponse As String

userResponse = MsgBox ("Do you want to save changes?"
If userResponse = vbCancel Then
'code if cancel is clicked
End If

OR if you are working on all 3 possible responses then

Select Case userResponse
Case vbOK
'code if OK clicked
Case vbNO
'code if NO clicked
Case vbCancel
'code if Cancel clicked
End Select

Sharad

"Dave" wrote in message
...
Basically I have a macro which contains a vbYesNoCancel
message box. I need
the macro to run a sub-routine when the user clicks 'cancel'.
At the moment
it just escapes out of the macro and stops. I don't seem to
be able to
manipulate the vbCancel as an elseif for the user response.
Is there any kind
of onCancel functionality or another way to run a sub-routine
when the user
clicks cancel? Or do I have to create my own dialog box from
scratch?







  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 212
Default how do I make a routine run after the 'cancel' butten is pressed .

This is what the Help on Message box tells:

"Displays a message in a dialog box, waits for the user to click a button,
and returns an Integer indicating which button the user clicked."

Sharad

"Chip Pearson" wrote in message
...
1. Dim userResponse As Integer


To be totally accurate, you should declare the variable as a Long.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com



"Sharad Naik" wrote in message
...
corrections:

1. Dim userResponse As Integer
"Though String will work, this is correct type.

2. MsgBox ("Do you want to save changes?", vbYesNoCancel)

But I realize that by the time I write this corrections, you already
got other better responses from Tom and an AlphaNumeric fellow ;-)

cheers

Sharad

"Sharad Naik" wrote in message
...
Enclose the Right part after msgbox in to paranthesis and assign the
response of msgbox to a variable

e.g

Dim userResponse As String

userResponse = MsgBox ("Do you want to save changes?"
If userResponse = vbCancel Then
'code if cancel is clicked
End If

OR if you are working on all 3 possible responses then

Select Case userResponse
Case vbOK
'code if OK clicked
Case vbNO
'code if NO clicked
Case vbCancel
'code if Cancel clicked
End Select

Sharad

"Dave" wrote in message
...
Basically I have a macro which contains a vbYesNoCancel message box. I
need
the macro to run a sub-routine when the user clicks 'cancel'. At the
moment
it just escapes out of the macro and stops. I don't seem to be able to
manipulate the vbCancel as an elseif for the user response. Is there
any kind
of onCancel functionality or another way to run a sub-routine when the
user
clicks cancel? Or do I have to create my own dialog box from scratch?








  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default how do I make a routine run after the 'cancel' butten is pressed .

"Help" has confused me in various places like this. I wonder if in this case
"integer" mearly means a whole number.

If I try
dim x
x = 12: x = "abc"
x = MsgBox(123, vbYesNoCancel)
and after clicking the msgbox I look in the Locals window, x is indicated as
Variant/Long

Regards,
Peter T


"Sharad Naik" wrote in message
...
This is what the Help on Message box tells:

"Displays a message in a dialog box, waits for the user to click a button,
and returns an Integer indicating which button the user clicked."

Sharad

"Chip Pearson" wrote in message
...
1. Dim userResponse As Integer


To be totally accurate, you should declare the variable as a Long.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com



"Sharad Naik" wrote in message
...
corrections:

1. Dim userResponse As Integer
"Though String will work, this is correct type.

2. MsgBox ("Do you want to save changes?", vbYesNoCancel)

But I realize that by the time I write this corrections, you already
got other better responses from Tom and an AlphaNumeric fellow ;-)

cheers

Sharad

"Sharad Naik" wrote in message
...
Enclose the Right part after msgbox in to paranthesis and assign the
response of msgbox to a variable

e.g

Dim userResponse As String

userResponse = MsgBox ("Do you want to save changes?"
If userResponse = vbCancel Then
'code if cancel is clicked
End If

OR if you are working on all 3 possible responses then

Select Case userResponse
Case vbOK
'code if OK clicked
Case vbNO
'code if NO clicked
Case vbCancel
'code if Cancel clicked
End Select

Sharad

"Dave" wrote in message
...
Basically I have a macro which contains a vbYesNoCancel message box.

I
need
the macro to run a sub-routine when the user clicks 'cancel'. At the
moment
it just escapes out of the macro and stops. I don't seem to be able

to
manipulate the vbCancel as an elseif for the user response. Is there
any kind
of onCancel functionality or another way to run a sub-routine when

the
user
clicks cancel? Or do I have to create my own dialog box from scratch?










  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default how do I make a routine run after the 'cancel' butten is pressed .

From the immediate window:

? typename(msgbox( vbYesNo))
Long

and the constants are typed as Long

Must be they haven't updated the help from the 16 bit version.

--
Regards,
Tom Ogilvy

"Sharad Naik" wrote in message
...
This is what the Help on Message box tells:

"Displays a message in a dialog box, waits for the user to click a button,
and returns an Integer indicating which button the user clicked."

Sharad

"Chip Pearson" wrote in message
...
1. Dim userResponse As Integer


To be totally accurate, you should declare the variable as a Long.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com



"Sharad Naik" wrote in message
...
corrections:

1. Dim userResponse As Integer
"Though String will work, this is correct type.

2. MsgBox ("Do you want to save changes?", vbYesNoCancel)

But I realize that by the time I write this corrections, you already
got other better responses from Tom and an AlphaNumeric fellow ;-)

cheers

Sharad

"Sharad Naik" wrote in message
...
Enclose the Right part after msgbox in to paranthesis and assign the
response of msgbox to a variable

e.g

Dim userResponse As String

userResponse = MsgBox ("Do you want to save changes?"
If userResponse = vbCancel Then
'code if cancel is clicked
End If

OR if you are working on all 3 possible responses then

Select Case userResponse
Case vbOK
'code if OK clicked
Case vbNO
'code if NO clicked
Case vbCancel
'code if Cancel clicked
End Select

Sharad

"Dave" wrote in message
...
Basically I have a macro which contains a vbYesNoCancel message box.

I
need
the macro to run a sub-routine when the user clicks 'cancel'. At the
moment
it just escapes out of the macro and stops. I don't seem to be able

to
manipulate the vbCancel as an elseif for the user response. Is there
any kind
of onCancel functionality or another way to run a sub-routine when

the
user
clicks cancel? Or do I have to create my own dialog box from scratch?










  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 212
Default how do I make a routine run after the 'cancel' butten is pressed .

Thanks Chip, forget my just previous post.
Sharad
"Sharad Naik" wrote in message
...
This is what the Help on Message box tells:

"Displays a message in a dialog box, waits for the user to click a button,
and returns an Integer indicating which button the user clicked."

Sharad

"Chip Pearson" wrote in message
...
1. Dim userResponse As Integer


To be totally accurate, you should declare the variable as a Long.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com



"Sharad Naik" wrote in message
...
corrections:

1. Dim userResponse As Integer
"Though String will work, this is correct type.

2. MsgBox ("Do you want to save changes?", vbYesNoCancel)

But I realize that by the time I write this corrections, you already
got other better responses from Tom and an AlphaNumeric fellow ;-)

cheers

Sharad

"Sharad Naik" wrote in message
...
Enclose the Right part after msgbox in to paranthesis and assign the
response of msgbox to a variable

e.g

Dim userResponse As String

userResponse = MsgBox ("Do you want to save changes?"
If userResponse = vbCancel Then
'code if cancel is clicked
End If

OR if you are working on all 3 possible responses then

Select Case userResponse
Case vbOK
'code if OK clicked
Case vbNO
'code if NO clicked
Case vbCancel
'code if Cancel clicked
End Select

Sharad

"Dave" wrote in message
...
Basically I have a macro which contains a vbYesNoCancel message box. I
need
the macro to run a sub-routine when the user clicks 'cancel'. At the
moment
it just escapes out of the macro and stops. I don't seem to be able to
manipulate the vbCancel as an elseif for the user response. Is there
any kind
of onCancel functionality or another way to run a sub-routine when the
user
clicks cancel? Or do I have to create my own dialog box from scratch?












  #11   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 400
Default how do I make a routine run after the 'cancel' butten is pressed .

This works for me; try to adapt it.

Sub xx()
Select Case MsgBox("MSG", vbCritical + vbYesNoCancel)
Case vbYes
MsgBox "yes"
Case vbNo
MsgBox "no"
Case vbCancel
MsgBox "cancel"
End Select
End Sub


"Dave" wrote:

Basically I have a macro which contains a vbYesNoCancel message box. I need
the macro to run a sub-routine when the user clicks 'cancel'. At the moment
it just escapes out of the macro and stops. I don't seem to be able to
manipulate the vbCancel as an elseif for the user response. Is there any kind
of onCancel functionality or another way to run a sub-routine when the user
clicks cancel? Or do I have to create my own dialog box from scratch?

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
Why should Service Pack make a difference in this routine? Lulu Excel Programming 0 October 26th 04 03:51 PM
TRAPPING PRESSED BUTTON jason Excel Programming 1 August 11th 04 01:33 PM
Which button was pressed? Adrian[_4_] Excel Programming 7 April 28th 04 04:55 PM
ComboBox DropDown when Key is pressed shrekut[_9_] Excel Programming 2 February 2nd 04 11:30 PM


All times are GMT +1. The time now is 01:17 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"