ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Putting a form into a macro string (https://www.excelbanter.com/excel-programming/416129-putting-form-into-macro-string.html)

scott

Putting a form into a macro string
 
I have created a macro in excel that clears all input data and assigned it to
a button. I need to put in a pop-up form that asks "Are you Sure" (yes/no).
Yes continues the macro; No puts you back into the spreadsheet.

Orion Cochrane

Putting a form into a macro string
 
Try this:
Confirm = MsgBox("Are you sure?", vbQuestion + vbYesNo, "Confirm Delete")
If Confirm = Yes Then
Application.Run (Macro)
Else: Exit Sub
End If

You can use either Exit Sub or End. The vbQuestion for the buttons syntax
adds a question mark icon to the left of the text in the message box ("Are
you sure?"). The beauty of using vbYesNo is that the user cannot close the
box without answering it. Just copy and paste the above code after your
procedure name. Hope that helps!
--
Please rate posts so we know when we have answered your questions. Thanks.


"scott" wrote:

I have created a macro in excel that clears all input data and assigned it to
a button. I need to put in a pop-up form that asks "Are you Sure" (yes/no).
Yes continues the macro; No puts you back into the spreadsheet.


Gord Dibben

Putting a form into a macro string
 
Sub test()
With Selection
If MsgBox(prompt:= _
"Are you sure you want to do this", _
Buttons:=vbYesNo) = vbNo Then End
..ClearContents
End With
End Sub


Gord Dibben MS Excel MVP

On Tue, 26 Aug 2008 12:18:02 -0700, scott
wrote:

I have created a macro in excel that clears all input data and assigned it to
a button. I need to put in a pop-up form that asks "Are you Sure" (yes/no).
Yes continues the macro; No puts you back into the spreadsheet.



Dave Peterson

Putting a form into a macro string
 
Or you could just ask the question at the top of your existing routine:

Option Explicit
Sub YourSubNameHere()

'your declaration statements
dim Resp as long 'added

resp = msgbox(Prompt:="Are you sure?", buttons:=vbyesno)

if resp = vbno then
exit sub
end if

'your real code here
End Sub



scott wrote:

I have created a macro in excel that clears all input data and assigned it to
a button. I need to put in a pop-up form that asks "Are you Sure" (yes/no).
Yes continues the macro; No puts you back into the spreadsheet.


--

Dave Peterson

scott

Putting a form into a macro string
 
Thanks for the info. It's almost there. The MsgBox pops up. No works
correctly, however when I select Yes nothing happens. How do I get it to
step back into the macro.

"Orion Cochrane" wrote:

Try this:
Confirm = MsgBox("Are you sure?", vbQuestion + vbYesNo, "Confirm Delete")
If Confirm = Yes Then
Application.Run (Macro)
Else: Exit Sub
End If

You can use either Exit Sub or End. The vbQuestion for the buttons syntax
adds a question mark icon to the left of the text in the message box ("Are
you sure?"). The beauty of using vbYesNo is that the user cannot close the
box without answering it. Just copy and paste the above code after your
procedure name. Hope that helps!
--
Please rate posts so we know when we have answered your questions. Thanks.


"scott" wrote:

I have created a macro in excel that clears all input data and assigned it to
a button. I need to put in a pop-up form that asks "Are you Sure" (yes/no).
Yes continues the macro; No puts you back into the spreadsheet.


Orion Cochrane

Putting a form into a macro string
 
That's what I said. Did you put the code at the beginning of your macro?
--
Please rate posts so we know when we have answered your questions. Thanks.


"Dave Peterson" wrote:

Or you could just ask the question at the top of your existing routine:

Option Explicit
Sub YourSubNameHere()

'your declaration statements
dim Resp as long 'added

resp = msgbox(Prompt:="Are you sure?", buttons:=vbyesno)

if resp = vbno then
exit sub
end if

'your real code here
End Sub



scott wrote:

I have created a macro in excel that clears all input data and assigned it to
a button. I need to put in a pop-up form that asks "Are you Sure" (yes/no).
Yes continues the macro; No puts you back into the spreadsheet.


--

Dave Peterson


scott

Putting a form into a macro string
 
Yes.

Sub Clear_Data()
'
' Clear_Data Macro
' Macro recorded 8/25/2008 by Scott D Webster
'

'
Confirm = MsgBox("Are you sure?", vbQuestion + vbYesNo, "Confirm Delete")
If Confirm = Yes Then
Application.Run (Macro)
Else: Exit Sub
End If


Sheets("1").Select
Range("A4:H42").Select

"Orion Cochrane" wrote:

That's what I said. Did you put the code at the beginning of your macro?
--
Please rate posts so we know when we have answered your questions. Thanks.


"Dave Peterson" wrote:

Or you could just ask the question at the top of your existing routine:

Option Explicit
Sub YourSubNameHere()

'your declaration statements
dim Resp as long 'added

resp = msgbox(Prompt:="Are you sure?", buttons:=vbyesno)

if resp = vbno then
exit sub
end if

'your real code here
End Sub



scott wrote:

I have created a macro in excel that clears all input data and assigned it to
a button. I need to put in a pop-up form that asks "Are you Sure" (yes/no).
Yes continues the macro; No puts you back into the spreadsheet.


--

Dave Peterson


Dave Peterson

Putting a form into a macro string
 
I was answering the original post--not responding to your message.

Your message wasn't there when I retrieved the headers, so I answered the
question.

Orion Cochrane wrote:

That's what I said. Did you put the code at the beginning of your macro?
--
Please rate posts so we know when we have answered your questions. Thanks.

"Dave Peterson" wrote:

Or you could just ask the question at the top of your existing routine:

Option Explicit
Sub YourSubNameHere()

'your declaration statements
dim Resp as long 'added

resp = msgbox(Prompt:="Are you sure?", buttons:=vbyesno)

if resp = vbno then
exit sub
end if

'your real code here
End Sub



scott wrote:

I have created a macro in excel that clears all input data and assigned it to
a button. I need to put in a pop-up form that asks "Are you Sure" (yes/no).
Yes continues the macro; No puts you back into the spreadsheet.


--

Dave Peterson


--

Dave Peterson

Dave Peterson

Putting a form into a macro string
 
And my code didn't call another subroutine. So there was a difference.

Orion Cochrane wrote:

That's what I said. Did you put the code at the beginning of your macro?
--
Please rate posts so we know when we have answered your questions. Thanks.

"Dave Peterson" wrote:

Or you could just ask the question at the top of your existing routine:

Option Explicit
Sub YourSubNameHere()

'your declaration statements
dim Resp as long 'added

resp = msgbox(Prompt:="Are you sure?", buttons:=vbyesno)

if resp = vbno then
exit sub
end if

'your real code here
End Sub



scott wrote:

I have created a macro in excel that clears all input data and assigned it to
a button. I need to put in a pop-up form that asks "Are you Sure" (yes/no).
Yes continues the macro; No puts you back into the spreadsheet.


--

Dave Peterson


--

Dave Peterson

Dave Peterson

Putting a form into a macro string
 
Option Explicit
Sub YourSubNameHere()

'your declaration statements
dim Resp as long 'added

resp = msgbox(Prompt:="Are you sure?", buttons:=vbyesno)

if resp = vbno then
exit sub
end if

worksheets("1").range("A4:H42").clearcontents

End Sub

scott wrote:

Yes.

Sub Clear_Data()
'
' Clear_Data Macro
' Macro recorded 8/25/2008 by Scott D Webster
'

'
Confirm = MsgBox("Are you sure?", vbQuestion + vbYesNo, "Confirm Delete")
If Confirm = Yes Then
Application.Run (Macro)
Else: Exit Sub
End If

Sheets("1").Select
Range("A4:H42").Select

"Orion Cochrane" wrote:

That's what I said. Did you put the code at the beginning of your macro?
--
Please rate posts so we know when we have answered your questions. Thanks.


"Dave Peterson" wrote:

Or you could just ask the question at the top of your existing routine:

Option Explicit
Sub YourSubNameHere()

'your declaration statements
dim Resp as long 'added

resp = msgbox(Prompt:="Are you sure?", buttons:=vbyesno)

if resp = vbno then
exit sub
end if

'your real code here
End Sub



scott wrote:

I have created a macro in excel that clears all input data and assigned it to
a button. I need to put in a pop-up form that asks "Are you Sure" (yes/no).
Yes continues the macro; No puts you back into the spreadsheet.

--

Dave Peterson


--

Dave Peterson

Dave Peterson

Putting a form into a macro string
 
Actually, I did see your reply. I just didn't see the reason to call the other
routine.

Orion Cochrane wrote:

That's what I said. Did you put the code at the beginning of your macro?
--
Please rate posts so we know when we have answered your questions. Thanks.

"Dave Peterson" wrote:

Or you could just ask the question at the top of your existing routine:

Option Explicit
Sub YourSubNameHere()

'your declaration statements
dim Resp as long 'added

resp = msgbox(Prompt:="Are you sure?", buttons:=vbyesno)

if resp = vbno then
exit sub
end if

'your real code here
End Sub



scott wrote:

I have created a macro in excel that clears all input data and assigned it to
a button. I need to put in a pop-up form that asks "Are you Sure" (yes/no).
Yes continues the macro; No puts you back into the spreadsheet.


--

Dave Peterson


--

Dave Peterson


All times are GMT +1. The time now is 09:56 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com