View Full Version : Run Macro help


SteveGr
08-13-2003, 12:11 PM
Option 1.) I would like to have a message box pop up to ask if I would like to run a macro when I move to a particular sheet in my workbook.

Option 2.) I could have a button on my sheet to run my macro.

I have already saved and named this macro, but what is the code to achieve either of these?

Thank you very much, Stevegr

Hayley Baxter
08-14-2003, 02:26 PM
The code to run a macro from a button on you from would look like this:

Private Sub cmdrunmacro_Click()
On Error GoTo Err_cmdrunmacro_Click

Dim stDocName As String

stDocName = "macroname"
DoCmd.RunMacro stDocName

Exit_cmdrunmacro_Click:
Exit Sub

Err_cmdrunmacro_Click:
MsgBox Err.Description
Resume Exit_cmdrunmacro_Click

End Sub

You don't really need to worry much about the code as you can do this via the wizard, the code above is what the wizard generates if you choose Miscelleanous and Run Macro.