Run Macro help

SteveGr

Registered User.
Local time
Today, 20:30
Joined
Aug 2, 2002
Messages
65
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
 
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.
 

Users who are viewing this thread

Back
Top Bottom