Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / December 2007

Tip: Looking for answers? Try searching our database.

Word Macro triggering run of other Word Macros

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
macromaker - 22 Dec 2007 03:04 GMT
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?
Graham Mayor - 22 Dec 2007 07:21 GMT
What is the point of this exercise?

Signature

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

My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

> 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?
fumei - 27 Dec 2007 21:07 GMT
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?????

>What is the point of this exercise?
>
>> 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?
macromaker - 28 Dec 2007 16:49 GMT
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]
> >> separate single letter.  Can a single Word macro randomly choose one
> >> of these 26 macros each time it is run?
fumei - 28 Dec 2007 19:33 GMT
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
[quoted text clipped - 6 lines]
>> >> separate single letter.  Can a single Word macro randomly choose one
>> >> of these 26 macros each time it is run?

Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.