Word Macro triggering run of other Word Macros

M

macromaker

I would like a Word macro when run to randomly choose a letter from the
alphabet. I have 26 other Word macros each that will type a separate single
letter. Can a single Word macro randomly choose one of these 26 macros each
time it is run?
 
G

Graham Mayor

What is the point of this exercise?

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
F

fumei via OfficeKB.com

Yes, I would like to know the purpose of this as well. For one thing, having
26 separate macros - one to type one character is crazy. Also, having "only"
26 means you are limiting yourself to either upper or lower case. To cover
both "H" and "h" would mean you would have to have 52 macros! Crazy.

Look up the Rnd function.

Sub TypeRandomLowercaseLetter()
Selection.TypeText Text:= _
Chr(Int((122 - 97 + 1) _
* Rnd + 97))
End Sub

will type a random lowercase letter. "a" = Chr(97) to "z" = Chr(122).

It gets the random number from the Rnd function, then uses that as a Chr, or
ASCII number, to type the actual letter.

However....again...what on earth is this for?????
 
M

macromaker

Yes, sounds crazy. This exercise is for this purpose: I often use a macro
that types text. I want to add variety this text. I have created several
other macros each typing a slightly different text. I would like a single
macro that can randomly run one of these macros. Is this possible?
 
F

fumei via OfficeKB.com

1. sorry, but that sounds strange and pointless, but then you did not bother
to actually answer the question, so I guess it will have to do.

2. "Is this possible?" Yes, quite possible. Not particularly difficult at
all. I suggest you actually read the posts. The answer is there with some
adjustments.

Essentially, make an array of your Sub names - and I still think this is a
very inefficient and silly way to do it - use the Rnd function to get a
random name out of the array...then run the darn thing.

I just did a test of 20 pointless Subs ( Msgbox "one", Msgbox "two"...etc.)
and wrote a randomizing procedure to call one of them - ummm, randomly - with
five lines of code. It is not difficult.

And no, I am not going to post it.
Yes, sounds crazy. This exercise is for this purpose: I often use a macro
that types text. I want to add variety this text. I have created several
other macros each typing a slightly different text. I would like a single
macro that can randomly run one of these macros. Is this possible?
Yes, I would like to know the purpose of this as well. For one thing, having
26 separate macros - one to type one character is crazy. Also, having "only"
[quoted text clipped - 22 lines]
 

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