Call Macro by Input Box

Pinaceous

Well-known Member
Joined
Jun 11, 2014
Messages
1,124
Office Version
  1. 365
Platform
  1. Windows
Hi All,

Is there a way to provide an Input Box/Message Box to prompt the user, which macro/sub to run?

For Example,

If they want
Code:
 Sub Sep()
to run they will input
in the Input Box/Message Box.

Many Thanks!
Pinaceous
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
you can always create a macro which calls macros based on input box value.

Like:
Code:
myValue = InputBox("Enter Macro Name", "", 1)

If myValue = "macro1" then
Call macro1
End if
 
Upvote 0
Another way:

Code:
  Application.Run InputBox("Macro?")
 
Upvote 0
Try this:
Code:
Sub Call_Me()
'Modified  10/13/2018  5:10:12 PM  EDT
On Error GoTo M
ans = InputBox("Enter Macro name")
Application.Run ans
Exit Sub
M:
MsgBox "You have no macro named  " & ans & " in the current workbook"
End Sub
 
Upvote 0
I have a lot of Macros.
I'm not able to remember all the shortcut keys to run these macros.
So I built a Userform

I open the Userform as Modeless so I can work on my workbook with the Userform displayed

On my Userform I have numerous Option buttons


I give the Option button caption a description reminding me what this script does
And then when I click on this Option Button the script assigned to that option button runs.

I store this Userform in My Personal Workbook and a script to Open The Userform in my Personal Workbook.

So now all I must remember is the Shortcut key that opens the Userform

And since I have maybe 40 some macros. I categorize my scripts and have a separate Multipage page on my Userform for each category of type script.

This works for me.

And by having my Userform in my Personal Workbook it's available when using any Workbook.

You may want to consider this if you have a whole lot of Macros and a bad memory.
 
Last edited:
Upvote 0
Try this:
Code:
Sub Call_Me()
'Modified  10/13/2018  5:10:12 PM  EDT
On Error GoTo M
ans = InputBox("Enter Macro name")
Application.Run ans
Exit Sub
M:
MsgBox "You have no macro named  " & ans & " in the current workbook"
End Sub


Actually shg,

If one were to press
in this sub, how would you have the input box MsgBox respond back, "you have canceled!".


Please let me know, if you can.

Many thanks,
Paul
 
Upvote 0
If you were to try my script you will see what it does.
If you want the message to say something else just modify the script.
You should be able to do that.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,177
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top