quick way to run a macro

G

Guest

I would like to run a macro just by typing a few characters.

It would be kinda like Autocorrect, but typing the characters
would run a macro, instead of replacing the characters.

Something with fields or Smart Tags, maybe ??

I know I can run a macro by typing a keyboard shortcut,
but I have dozens of macros, so it's hard to make up
good shortcut key sequences. Typing a word would be
much easier (more mnemonic, anyway).

thanks
 
H

Herb Tyson [MVP]

Well... you could write a macro that selects the last-typed word, and uses
it as the name of the macro to run.

Or, if you can settle for two-letter mnemonics, you can assign two-letter
keyboard shorts. For example, suppose you have a macro to strip hard
paragraph marks out of of block of text, you could assign Alt+pa (i.e.,
you'd type Alt+p immediately followed by a--shows up in the Press new
shortcut key as Alt+P,A).
 
G

Guest

Brilliant.
Sounds like that would be a very useful general-purpose
utility. Has anyone written anything like this before ??

thanks
 
G

Greg Maxey

How about something like:

Sub SelectMacro()

Dim MyMacro As String
MyMacro = InputBox("Type macro name.", "Run")
Application.Run MacroName:=MyMacro

End Sub

and assign it to a simple keyboard shortcut
 
G

Guest

Seems like grabbing the text from the document is a lot more
flexible than entering it in an InputBox, and invocation is
a bit slicker.

I was thinking I could write macros with arguments to be used
in this way, too. If I grab the text from the document, I can type
\frac 3 7, hit my magic macro key, and then my "interface" macro
will
(a) read the three "words" \frac 3 7
(b) run a macro called frac, passing 3 and 7 as arguments
(this will insert a MathType fraction 3/7).

thanks again
 
G

Greg Maxey

OK, You could type frac and run this code and your macro named frac would
run. I suppose that you could also come up with code to do what you
described. It is a bit over my head, but I think you would next have to
break your string down into component parts: Macroname, numerator, and
denominator.



Sub RunNamedMacro()

Dim pMacroName As String

Selection.MoveStart Unit:=wdWord, Count:=-1
pMacroName = Selection.Range
Application.Run MacroName:=pMacroName

End Sub
 

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

Top