Share via

Warning before running a macro

Anonymous
2011-03-22T05:20:39+00:00

Hi Everyone,  would appreciate some help.  I have a command button to run a macro, is it possible to create a warning before running the macro? Like "Are you sure you want to run Macro". 

Thanks for your continuous suport

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

HansV 462.6K Reputation points
2011-03-22T06:43:27+00:00

You can build the prompt into the macro itself:

Sub MyMacro()

    If MsgBox("Are you sure that you want to run a macro?", _

            vbYesNo + vbQuestion) = vbNo Then

        Exit Sub

    End If

    ' Your code goes here

    ...

End Sub

Was this answer helpful?

5 people found this answer helpful.
0 comments No comments

9 additional answers

Sort by: Most helpful
  1. Anonymous
    2011-08-05T18:58:50+00:00

    I missed that this post is about Excel. I'm looking for this functionality in Access. I thought I found something on msgbox there, but couldn't make it work.

    Was this answer helpful?

    0 comments No comments
  2. HansV 462.6K Reputation points
    2011-08-05T17:53:53+00:00

    If the macro is stored in the active workbook:

    Press Alt+F8 to display the Macro dialog.

    Select the macro in the list.

    Click Edit.

    This won't work for macros in your personal macro workbook Personal.xls(b). To edit those:

    Press Alt+F11 to activate the Visual Basic Editor.

    Expand VBAProject (PERSONAL.XLSB) (the B is only present if you're using Excel 2007 or later).

    Expand Modules.

    Double-click one of the modules under Modules to view and edit the code in that module.

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2011-08-05T17:41:50+00:00

    I have built a lot of macros using the user interface but can't figure out how to get to the code behind it to add this to one of my macros.

    Was this answer helpful?

    0 comments No comments
  4. Anonymous
    2011-03-22T20:00:24+00:00

    Thank You it worked briliantly.

    Was this answer helpful?

    0 comments No comments