Re: Repeating Loop Until End of Document
- From: dlmaley <dlmaley@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Wed, 21 Jun 2006 09:34:10 -0700
Greg, thanks so much! Yes this explains it. Your suggestion was awesome and
so much easier than trying to use a loop. Changing the font size did not
actually bump down the block of text so I altered what you gave me as shown
below, and it worked perfectly!
Dim i As Long
For i = 20 To ActiveDocument.Paragraphs.Count Step 66
With ActiveDocument.Paragraphs(i)
.LineSpacingRule = wdLineSpaceExactly
.LineSpacing = 16
End With
Next i
End Sub
"Greg Maxey" wrote:
Well.
Dim i As Long - Declared the variable i as Long.
Dim oPar as Paragraph is redundant and you can delete it. I was thinking
one thing and doing another.
For i = 20 to ActiveDocument.Paragraphs.Count Step 66
That means when i = 20 and each increment of 66 (e.g. 86, 152, 208, etc.) up
to the total number of paragraphs then perform the next statement
ActiveDocument.Paragraphs(i).Range.Font.Size = 16
That means for paragraph number 20 and 86 and 152, etc. set the font size of
the paragraph range to 16
Next i
Couunt up 1
So starting at i = 20 the 20th paragraph range font size is set to 16
Then skip paragraphs 21 trough 85
Then work on paragraph 86
So on and so on
Does that explain it?
--
Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.
dlmaley wrote:
Greg: Could you explain which each line of code is doing? I need to
be able to explain to my boss what we are doing to the client's file.
Thanks.
"Greg Maxey" wrote:
A loop for what you are actually trying to do could be complicated.
How about:
Sub Test()
Dim i As Long
Dim oPar As Paragraph
For i = 20 To ActiveDocument.Paragraphs.Count Step 66
ActiveDocument.Paragraphs(i).Range.Font.Size = 16
Next i
End Sub
--
Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.
dlmaley wrote:
Sorry I just realized I left out a line. This macro that I tried is
like this:
Sub Macro3()
Dim X As Integer
X=0
Do Until X = 1000000
Application.Run MacroName:="Macro5"
Loop
MsgBox ("Macro Finished!")
End Sub
"dlmaley" wrote:
Paragraphs (hard returns that the client put in to position the
text :-|).
"Cindy Meister" wrote:
Yes, that does clarify :-)
One more question, then, to be really sure: Are these lines or
paragraphs? (I'd assume paragraphs, but it makes a big difference
on how to approach the problem, and how efficiently it can be
coded.) --
-- Cindy
"dlmaley" wrote:
No, we are not trying to make every paragraph exactly 16 pt. The
majority of the document is exactly 12 pt. Starting at Line 20
and every 66th line down until the end of the document needs to
be changed to exactly 16 pt. After we do this we will also need
to loop to change every 66th line down from Line 63 to exactly 8
pt. We are using this to position data on a preprinted form. We
have to work with this data the way it comes to use from our
client so what we are doing is moving a certain part of the data
down at Line 20 in every record and then up at Line 63 in every
record so it falls correclty on the preprinted form. Sorry I
wasn't clear. Hope that helps.
Thanks!
"Cindy Meister" wrote:
Hmm. Is the purpose really to just make sure every paragraph is
formatted with 16 pt font size? In that case, this should work:
Sub Format16Pt()
ActiveDocument.Range.Font.Size = 16
End Sub
If that's not quite what you need, please explain the END RESULT
you require (don't worry how to get there, just tell us what you
need as a result). --
-- Cindy
"dlmaley" wrote:
I have read the other posts regarding this and did not find
anything that would help me. I think I'm starting to get there
is no easy answer. Here is what I have. Forgive me if it is
awful...I am just starting to learn this.
Sub Macro3()
Dim X As Integer
Do Until X = 1000000
Application.Run MacroName:="Macro5"
Loop
MsgBox ("Macro Finished!")
End Sub
I am trying to loop a recorded macro (Macro5) that goes down 66
lines with the Goto command and then formats that line with
paragraph formatting Exactly 16Pt. I need this to keep going
down 66 lines and formatting the line it hits until the end of
the document. My husband suggested the code shown above and had
me put X=1000000 going down 66 lines from the last record to
try to get it to end there. When I run this, I never see the
Macro Finished! message, and the cursor flashes at the end as
though it is going back and forth between the last 2 carriage
returns. When I stop the macro, and check some of the records,
the 66th line is formatted correctly. I can use this as is if
I can get it to stop looping, but I would prefer the correct
code to make it loop until the end of document or the end of
the file. If this goes back to the top and starts formatting
66 lines down from the top of the document, it will mess up
the positioning of the data. Any suggestions would be
appreciated! Thanks!
- Follow-Ups:
- Re: Repeating Loop Until End of Document
- From: Greg Maxey
- Re: Repeating Loop Until End of Document
- References:
- RE: Repeating Loop Until End of Document
- From: Cindy Meister
- RE: Repeating Loop Until End of Document
- From: dlmaley
- RE: Repeating Loop Until End of Document
- From: dlmaley
- Re: Repeating Loop Until End of Document
- From: Greg Maxey
- Re: Repeating Loop Until End of Document
- From: dlmaley
- Re: Repeating Loop Until End of Document
- From: Greg Maxey
- RE: Repeating Loop Until End of Document
- Prev by Date: creating a macro with a document containing a footer
- Next by Date: Re: Default File Open Location
- Previous by thread: Re: Repeating Loop Until End of Document
- Next by thread: Re: Repeating Loop Until End of Document
- Index(es):
Relevant Pages
|