Option to continue or cancel

K

Ken G

I have a macro which deletes completed jobs from a spreadsheet. Since this action is not reversible I'd like an option box of some sort to appear when the macro is first invoked to say that the action is not reversible and then have a proceed or cancel option which would either execute the macro or end out of it

Thanks
Ken G.
 
C

Charles

KenG


Here is a bit of code you could use.

Sub msg_box()
Dim ans As String

ans = MsgBox("Attention you are about to delete are you sure you wan
to?", vbYesNo)
If ans = vbYes Then
'your code
ElseIf ans = vbNo Then
Exit Sub
End If
End Sub

Charle
 
M

mudraker

Try

Select Case MsgBox("Please Confirm " _
& "You Wish To Permantley Delete This Record", _
vbYesNo + vbExclamation + vbDefaultButton2)
Case vbYes
Delete Record code here
End Selec
 
D

David Adamson

Ken,

Adapt this. It is just a Msg box that then when "yes" is slected it closes
down any open workbook

----------------
Dim Msg, Style, Title, Response
Msg = "Wellcome to the proposed outline" & Chr(13) & _
"It is advised that you should close all other open workbooks to prevent
potential conflict with this model." & Chr(13) & _
"To close and save other spreadsheets press YES?" & Chr(13) & _
"To ignore this warning and keep existing workbooks open, press NO" '
Define message."

Style = vbYesNo + vbExclamation + vbDefaultButton2 ' Define buttons.
Title = "Selection" ' Define title.
'Display message.
Response = MsgBox(Msg, Style, Title)
If Response = vbYes Then ' User chose Yes.

For Each wkb In Workbooks
If Not wkb Is ThisWorkbook Then
wkb.Close savechanges:=True
End If
Next wkb
End If


Ken G said:
I have a macro which deletes completed jobs from a spreadsheet. Since this
action is not reversible I'd like an option box of some sort to appear when
the macro is first invoked to say that the action is not reversible and then
have a proceed or cancel option which would either execute the macro or end
out of it.
 
Top