I need help with writing a "Do Until" macro. I am inserting a text file
(that changes daily) and need to insert spaces at fixed lengths in each line.
I want to start on the first line and stop the macro at the end of the file.
The macro is:

Sub Insert_Spaces()
'
' Insert_Spaces Macro
' Macro recorded 9/7/2005 by keenpar
'
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.TypeText Text:=" "
Selection.MoveRight Unit:=wdCharacter, Count:=7
Selection.TypeText Text:=" "
Selection.MoveRight Unit:=wdCharacter, Count:=16
Selection.TypeText Text:=" "
Selection.MoveDown Unit:=wdLine, Count:=1
Selection.HomeKey Unit:=wdLine
End Sub

Any help will be most appreciated.
Thanks
--
Jerry Keenan

Re: Need help with a looping macro by JerryKeenan

JerryKeenan
Sat Sep 24 15:54:02 CDT 2005

Thank you Eddie,

I should have told you I am a real novice at this. If you can't record the
macro, I have a problem. I'm sure your solutions would work, but I need more
hand holding. I would like to see both of your solutions. Here is a sample
file. It does have paragraph marks. Can you show me the macro you would use?

5094765800000000002602431790055555
5091556200000000002554151790000004
5004765800000000002605331790000005
5001556200000000002559151790000006
5000600000000000002572271910000009
5000300000000000002577881910000010
5000600000000000002575271910000011
5000300000000000002575881910000012
5000600000000000002572271910029292
5000300000000000002577881910000010
5000600000000000002575271910000011
5000300000000000002575881910000012
5000600000000000002572271910000009

--
Jerry Keenan


"Edward Thrashcort" wrote:

> It depends how your document is structured.
> Are lines separated by paragraph marks?
>
> If so, you could continue to use the selection object with
>
> Dim aPara as Paragraph
> For Each aPara In ActiveDocument.Paragraphs
> aPara.Select
> 'ETC
> Next
>
>
> Alternatively you could use
> Do.. Loop until ...
> in which case it may be better to use a Range object and test ot for end of
> Document.
>
> There are other more elegant methods, I'm sure
>
> Eddie
>

Re: Need help with a looping macro by JerryKeenan

JerryKeenan
Sat Sep 24 16:52:01 CDT 2005

Thanks again,

I'm traveling this evening and will try it when I get to Savannah. I really
appreciate your help.
--
Jerry Keenan


"Edward Thrashcort" wrote:

> OK, I'll make it fit with what you have recorded
>
> Sub PushSpaces()
> Dim aPara As Paragraph
> For Each aPara In ActiveDocument.Paragraphs
> aPara.Range.Select
> With Selection
> .Collapse
> .MoveRight Unit:=wdCharacter, Count:=1
> .TypeText Text:=" "
> .MoveRight Unit:=wdCharacter, Count:=7
> .TypeText Text:=" "
> .MoveRight Unit:=wdCharacter, Count:=16
> .TypeText Text:=" "
> .MoveDown Unit:=wdLine, Count:=1
> .HomeKey Unit:=wdLine
> End With
> Next
> End Sub
>
>
>
> Eddie
>

Re: Need help with a looping macro by Helmut

Helmut
Sat Sep 24 17:31:49 CDT 2005

Hi Jerry,

like this:

Sub Macro7()
Dim oPrg As Paragraph
Dim rTmp As Range
For Each oPrg In ActiveDocument.Paragraphs
Set rTmp = oPrg.Range
rTmp.End = rTmp.Start + 1
rTmp.InsertAfter " "
rTmp.End = rTmp.End + 7
rTmp.InsertAfter " "
rTmp.End = rTmp.End + 16
rTmp.InsertAfter " "
Next
End Sub

Make sure, that there is no empty paragraph nowhere.
Not at the doc's start and not at the doc's end.

One could even do it without rTmp.
But that's a matter of style.

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"


Re: Need help with a looping macro by JerryKeenan

JerryKeenan
Sun Sep 25 08:10:11 CDT 2005

Very cool. Thanks so much and have a great day.
--
Jerry Keenan


"Edward Thrashcort" wrote:

> OK, I'll make it fit with what you have recorded
>
> Sub PushSpaces()
> Dim aPara As Paragraph
> For Each aPara In ActiveDocument.Paragraphs
> aPara.Range.Select
> With Selection
> .Collapse
> .MoveRight Unit:=wdCharacter, Count:=1
> .TypeText Text:=" "
> .MoveRight Unit:=wdCharacter, Count:=7
> .TypeText Text:=" "
> .MoveRight Unit:=wdCharacter, Count:=16
> .TypeText Text:=" "
> .MoveDown Unit:=wdLine, Count:=1
> .HomeKey Unit:=wdLine
> End With
> Next
> End Sub
>
>
>
> Eddie
>

Re: Need help with a looping macro by JerryKeenan

JerryKeenan
Sun Sep 25 08:15:01 CDT 2005

Works great. Thanks so much. Hope your weather is as good in Bavaria as it
is in Savannah Georgia today.
--
Jerry Keenan


"Helmut Weber" wrote:

> Hi Jerry,
>
> like this:
>
> Sub Macro7()
> Dim oPrg As Paragraph
> Dim rTmp As Range
> For Each oPrg In ActiveDocument.Paragraphs
> Set rTmp = oPrg.Range
> rTmp.End = rTmp.Start + 1
> rTmp.InsertAfter " "
> rTmp.End = rTmp.End + 7
> rTmp.InsertAfter " "
> rTmp.End = rTmp.End + 16
> rTmp.InsertAfter " "
> Next
> End Sub
>
> Make sure, that there is no empty paragraph nowhere.
> Not at the doc's start and not at the doc's end.
>
> One could even do it without rTmp.
> But that's a matter of style.
>
> --
> Greetings from Bavaria, Germany
>
> Helmut Weber, MVP WordVBA
>
> Win XP, Office 2003
> "red.sys" & Chr$(64) & "t-online.de"
>
>