Can someone SHOW me how to make my macro REPEAT?

J

Jim In Minneapolis

Hi! Can anybody tell me how to make a macro keep REPEATING until it reaches
the end of the list?

Here's my macro . . . it works fine, but it only executes 'once' and then
stops. I need it to KEEP repeating. Can anyone please SHOW me how to MODIFY
it so it does what I need?

Selection.TypeText Text:=""""
Selection.EndKey Unit:=wdLine
Selection.TypeText Text:=""""
Selection.MoveRight Unit:=wdCharacter, Count:=1

What I want to do . . .

I have a column of words (just 1 word on a line) and I need to put QUOTES
around each word

Example:

apple
orange
banana

becomes

"apple"
"orange"
"banana"

So we want the macro to go down the entire list of words, and keep
repeating, and then stop when it finally gets to the end.

If anyone can SHOW me how to MODIFY my original macro, I'll sure be grateful!

Thanks again.

Jim
 
G

Greg Maxey

Jim,

Select the list and try this:

Sub ScratchMacro()
Dim oPara
Dim oRng As Range
For Each oPara In Selection.Range.Paragraphs
Set oRng = oPara.Range
oRng.MoveEnd wdCharacter, -1
oRng.Text = Chr(34) & oRng.Text & Chr(34)
Next
End Sub
 
J

Jim In Minneapolis

THANKS, Greg!

Your're a genius. Seriously!

You've saved my life.

God bless you.

Jim
 
G

Greg Maxey

That is twice this month that someone has made that claim. Helpful, I try
to be. A genius, emphatically not. Glad I could help.
 
T

Tony Jollans

Greg's code is fine but you really don't need a loop, or even code, to do
this.

Assuming your lines are ended with paragraph marks, you can use Find &
Replace ...

Check "Use Wildcards"
Find (<*>)(^13)
Replace "\1"\2
Hit Replace All

You can record code if you want it - and it should be faster than looping
through paragraphs
 

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