Confirmation box

  • Thread starter Thread starter alex1982
  • Start date Start date
A

alex1982

I have writen a macro, but was just wondering if it is possible to add
confirmation box to popup at the start incase someone presses the butto
by mistake
 
Here is my Before Print sub which uses a Message Box to make sure tha
the user has updated the weekly data before they print the report no
sure what your macro is doing but by changing the workbook event o
adapting the code it should be what you need or at least a step in th
right direction

Private Sub Workbook_BeforePrint(Cancel As Boolean)

Dim wk As Worksheet
Dim Config As Integer
Dim Ans As Integer

For Each wk In Worksheets
wk.Calculate
Next

Config = vbYesNo + vbQuestion + vbDefaultButton1
Ans = MsgBox("Have you updated the weekly data?", Config, "Ensur
correct data")

If Ans = vbNo Then Cancel = True

If Ans = vbYes Then Cancel = False

End Sub

Regards

Adria
 
Hi Alex,

This is one way...

Public Sub MyMacro()
Dim Check As VbMsgBoxResult
Check = MsgBox("Are you sure you want this macro to run?", vbYesNo)
If Check = vbYes Then
'Code Here
End If
End Sub

Just make sure there is no code between End If and End Sub.

Ken Johnson
 
Hi Alex,

Dim Check As VbMsgBoxResult
Check = MsgBox("Are you sure you want this macro to run?", vbYesNo)
If Check = vbYes Then

could be at the start of your code, then straight after the last line
of your code (but before the End Sub line) the "End If" line.

This way, your code is only run if the user clicks the "Yes" button.
When the "No" button is clicked the code jumps to the "End If" then the
End Sub, so nothing happens.

Ken Johnson
 
Thanks, i managed to work it out. This is the first time i've really
tried to use macros for anything. :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top