How do I repeat a macro

H

heather

I know it must be simple, but how can a macro be repeated, say, 50 times?
Thanks! -h
 
D

Doug Robbins - Word MVP

Hi Heather,

Tell us what you macro is supposed to be doing. There's probably a better
way. However the following code will run macro Sub a() 50 times

Sub b()
Dim i As Integer
For i = 1 To 50
Call a
Next i
End Sub

Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP
 
G

Greg Maxey

Heather,

Adapted this from something Dave Lett posted previously

Sub RepeatMacro()

Dim iRepeat As Integer
Dim iTimes As Integer
iTimes = InputBox(Prompt:="How many times do you want to repeat macro?")
For iRepeat = 1 To iTimes
Selection.TypeText Text:="Test."
Selection.TypeParagraph
Next iRepeat
End Sub

This macro will ask you how many times to repeat and then perform the
action. In this case it inserts Test. and starts a new paragraph.

--
Greg Maxey
A peer in "peer to peer" support
Rockledge, FL
E-mail for additional help, within reason, if you like. I may not
always solve your problem, but no charge if I do. To e-mail, first edit
out the "w...spam" in the displayed address.
 
H

heather

Perfect! Both macros work great. Thanks to you & Doug! -h
(but isn't there a way to simply repeat any command in Word a set # of
times?)
| Heather,
|
| Adapted this from something Dave Lett posted previously
|
| Sub RepeatMacro()
|
| Dim iRepeat As Integer
| Dim iTimes As Integer
| iTimes = InputBox(Prompt:="How many times do you want to repeat macro?")
| For iRepeat = 1 To iTimes
| Selection.TypeText Text:="Test."
| Selection.TypeParagraph
| Next iRepeat
| End Sub
|
| This macro will ask you how many times to repeat and then perform the
| action. In this case it inserts Test. and starts a new paragraph.
|
| --
| Greg Maxey
| A peer in "peer to peer" support
| Rockledge, FL
| E-mail for additional help, within reason, if you like. I may not
| always solve your problem, but no charge if I do. To e-mail, first edit
| out the "w...spam" in the displayed address.
|
| heather wrote:
| > I know it must be simple, but how can a macro be repeated, say, 50
| > times? Thanks! -h
|
|
 
S

Suzanne S. Barnhill

F4 will repeat, but you have to press it for each repetition. There is no
command in Word like the one in WP that lets you repeat x times.

--
Suzanne S. Barnhill
Microsoft MVP (Word)
Words into Type
Fairhope, Alabama USA
Word MVP FAQ site: http://www.mvps.org/word
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
 
L

Larry

You can repeat a single line of code any number of times, but that's not
necessarily the same as repeating an entire macro:

Selection.TypeText "Hello, world." & vbCr
Repeat (10)

Larry
 
H

heather

Thank you, Suzanne. You've confirmed that what I've been looking for just
isn't there. WP was sooo much easier. -h
| F4 will repeat, but you have to press it for each repetition. There is no
| command in Word like the one in WP that lets you repeat x times.
|
| --
| Suzanne S. Barnhill
| Microsoft MVP (Word)
| Words into Type
| Fairhope, Alabama USA
| Word MVP FAQ site: http://www.mvps.org/word
| Email cannot be acknowledged; please post all follow-ups to the newsgroup
so
| all may benefit.
|
| | > Perfect! Both macros work great. Thanks to you & Doug! -h
| > (but isn't there a way to simply repeat any command in Word a set # of
| > times?)
| > | > | Heather,
| > |
| > | Adapted this from something Dave Lett posted previously
| > |
| > | Sub RepeatMacro()
| > |
| > | Dim iRepeat As Integer
| > | Dim iTimes As Integer
| > | iTimes = InputBox(Prompt:="How many times do you want to repeat
macro?")
| > | For iRepeat = 1 To iTimes
| > | Selection.TypeText Text:="Test."
| > | Selection.TypeParagraph
| > | Next iRepeat
| > | End Sub
| > |
| > | This macro will ask you how many times to repeat and then perform the
| > | action. In this case it inserts Test. and starts a new paragraph.
| > |
| > | --
| > | Greg Maxey
| > | A peer in "peer to peer" support
| > | Rockledge, FL
| > | E-mail for additional help, within reason, if you like. I may not
| > | always solve your problem, but no charge if I do. To e-mail, first
edit
| > | out the "w...spam" in the displayed address.
| > |
| > | heather wrote:
| > | > I know it must be simple, but how can a macro be repeated, say, 50
| > | > times? Thanks! -h
| > |
| > |
| >
| >
|
 

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