Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 21
Default OK/Cancel box functionality?

I have a snippet of code attached to a button so that when you click the
button the workbook is emailed to a specified email address. However, I
would like to add a confirmation popup before any code is executed. I've
gotten as far as:

Dim response As Long
response = MsgBox(prompt:="Are you sure you would like to submit?",
Buttons:=vbOKCancel)

When I click OK, the code executes as it should. However, when I click
cancel, the code still executes. Can't figure out how to code for cancel.
I want it to do nothing, and simply return to the form on which the button is
embedded. How do I do this?
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 3,365
Default OK/Cancel box functionality?

A couple of ways to do it. Going along with what you've started, you need to
test the contents of 'response'

Dim response As Long
response = MsgBox(prompt:="Are you sure you would like to submit?",
Buttons:=vbOKCancel)
If response < vbOK Then
Exit Sub
End If
.... code to send the file goes here

or a more abbreviated version that doesn't have to use the added variable
'response':

If MsgBox("Are you sure you would like to submit?", _
vbOKCancel+vbQuestion,"Confirm Emailing") < vbOK Then
Exit Sub
End If
....

"sycsummit" wrote:

I have a snippet of code attached to a button so that when you click the
button the workbook is emailed to a specified email address. However, I
would like to add a confirmation popup before any code is executed. I've
gotten as far as:

Dim response As Long
response = MsgBox(prompt:="Are you sure you would like to submit?",
Buttons:=vbOKCancel)

When I click OK, the code executes as it should. However, when I click
cancel, the code still executes. Can't figure out how to code for cancel.
I want it to do nothing, and simply return to the form on which the button is
embedded. How do I do this?

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
Input Box Cancel Jase Excel Discussion (Misc queries) 2 September 15th 08 11:42 PM
cancel save lawson Excel Discussion (Misc queries) 1 October 11th 07 11:00 PM
cancel input ME @ Home Excel Discussion (Misc queries) 1 February 22nd 06 09:49 AM
can I cancel a save juls!1601 Excel Discussion (Misc queries) 2 February 16th 06 01:03 AM
Read Only - How to Cancel? Glenn Excel Discussion (Misc queries) 1 August 26th 05 06:23 PM


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

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"