Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Run a macro from a vbyesno Msg box response

Hello
I am trying to create a msg box so that when the user clicks 'yes' it
triggers a macro to run. However at the moment when I click Yes the script
ends and no macro is run - the same happens for No and Cancel but that is
correct for those selections. The code I'm trying is shown below and sits at
the start of the marco in question. I'm new to this so have not sure what to
do. Any ideas?

Sub clean()
Msg = "Have you saved the current file data?"
Response = MsgBox(Msg, vbYesNoCancel)

If Response = vbYes Then
'<=== runactivemacro clean()
Exit Sub
End If

If Response = vbNo Then
MsgBox "Use the Save As function to Save the file before cleaning the sheet"
Exit Sub
End If

If Response = vbCancel Then
MsgBox "Action Cancelled"
Exit Sub
End If


' clean Macro
' Macro recorded etc etc then all the macro detail is here
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,420
Default Run a macro from a vbyesno Msg box response

This works fine for me

Sub Clean()
Dim Msg As String
Dim Response As Long

Msg = "Have you saved the current file data?"
Response = MsgBox(Msg, vbYesNoCancel)

If Response = vbYes Then
Call Clean2
ElseIf Response = vbNo Then
MsgBox "Use the Save As function to Save the file before cleaning
the sheet"
ElseIf Response = vbCancel Then
MsgBox "Action Cancelled"
End If

End Sub

Sub Clean2()
MsgBox "Clean2"
End Sub



--
__________________________________
HTH

Bob

"Binngo" wrote in message
...
Hello
I am trying to create a msg box so that when the user clicks 'yes' it
triggers a macro to run. However at the moment when I click Yes the
script
ends and no macro is run - the same happens for No and Cancel but that is
correct for those selections. The code I'm trying is shown below and sits
at
the start of the marco in question. I'm new to this so have not sure what
to
do. Any ideas?

Sub clean()
Msg = "Have you saved the current file data?"
Response = MsgBox(Msg, vbYesNoCancel)

If Response = vbYes Then
'<=== runactivemacro clean()
Exit Sub
End If

If Response = vbNo Then
MsgBox "Use the Save As function to Save the file before cleaning the
sheet"
Exit Sub
End If

If Response = vbCancel Then
MsgBox "Action Cancelled"
Exit Sub
End If


' clean Macro
' Macro recorded etc etc then all the macro detail is here



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 78
Default Run a macro from a vbyesno Msg box response

Hi Binngo,

A other way to do could be:

Sub Clean()
Msg = "Have you saved the current file data?"
Select Case MsgBox(Msg, vbYesNoCancel)
Case vbYes
Call Clean2
Case vbNo
MsgBox "Use the Save As function to " & _
"Save the file before cleaning the sheet"
Case Else
MsgBox "Action Cancelled"
End Select

End Sub

Sub Clean2()
MsgBox "Clean2"
End Sub

HTH,

Wouter
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Run a macro from a vbyesno Msg box response

Thanks both I will give those a try.

bw Binngo


"Binngo" wrote:

Hello
I am trying to create a msg box so that when the user clicks 'yes' it
triggers a macro to run. However at the moment when I click Yes the script
ends and no macro is run - the same happens for No and Cancel but that is
correct for those selections. The code I'm trying is shown below and sits at
the start of the marco in question. I'm new to this so have not sure what to
do. Any ideas?

Sub clean()
Msg = "Have you saved the current file data?"
Response = MsgBox(Msg, vbYesNoCancel)

If Response = vbYes Then
'<=== runactivemacro clean()
Exit Sub
End If

If Response = vbNo Then
MsgBox "Use the Save As function to Save the file before cleaning the sheet"
Exit Sub
End If

If Response = vbCancel Then
MsgBox "Action Cancelled"
Exit Sub
End If


' clean Macro
' Macro recorded etc etc then all the macro detail is here

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
add vbyesno to existing macro SteveDB1 Excel Programming 6 September 8th 08 10:42 PM
How do I transform a word response to a numeric response? kanegaro Excel Discussion (Misc queries) 0 January 11th 08 05:08 PM
How do I set up a daily call out response response register? Pule Excel Worksheet Functions 1 October 7th 07 01:34 PM
Selecting a response on a dialogue box from a Macro ChemicalJasper Excel Discussion (Misc queries) 2 January 4th 07 02:08 PM
Macro for Customer response time Bren.ie Excel Programming 2 November 18th 03 09:42 AM


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