What code do I need to add for 100's pages?

S

Steve Frell

I recorded a macro to do a simple task:

To count 14 lines, then break with 2 or 3 lines,
then continue - so I simply have pages of paragraphs
all of 14 lines.

Code:
--------------------------------------
Sub MAIN
InsertPara
FormatPageNumber .ChapterNumber = 0, .NumRestart = 0, .NumFormat
= 0, .StartingNum = "0", .Level = 0, .Separator = 0
InsertPageNumbers .Type = 0, .Position = 1, .FirstPage = 1
LineDown 12
InsertPara
InsertPara
InsertPara
LineDown 12
InsertPara
InsertPara
InsertPara
LineDown 12
InsertPara
InsertPara
InsertPara
LineDown 12
InsertPara
InsertPara
InsertPara
LineDown 3
LineUp 3
EditClear - 3
InsertPara
InsertPara
EditSelectAll
CenterPara
End Sub
-------------------------------------------

However, this only works for 1 page. What code do
I need to add for the macro to work for the whole
document (maybe 100 pages long)?

Thanks
Steve.
 
S

Steve Frell

What are you trying to do?

I've got 100's
pages of solid
text. The code I
posted
formats the FIRST
page ONLY into 4
paragraphs of 12
lines each.

For each subsequent
page I want to
format, I have to
place
the cursor at the
beginning of the
page and run the
macro.

I need code to add
to my code, that
after one click or
command, will run
the macro for
dozens or hundreds
or
however many pages.
 
D

Dave Lett

Hi Steve,

If you're happy with your existing code, then you can use something like the
following:

Dim iCount as Integer
For iCount = 1 to 100
'''insert your routine here
Selection.InsertBreak Type:=wdPageBreak
Next iCount

However, when Jezebel asked "What are you trying to do?" he/she did so
because what you have outlined looks a little...well, screwy to someone with
VBA experience. Jezebel probably asked the question in the hopes of offering
a more efficient solution to meet your goals.

HTH,
Dave
 
H

Helmut Weber

Hi,

the problem you got is that which each
formatting or inserting lines the document grows.

Unless you add more text than one page can hold,
the process must get to a stop in the end.
if you add more text than one page can hold,
you are in an infinite loop.

Like this, where DoYourThing is your
possible inserting and formatting:

Sub test8976()
Dim l1 As Long
Dim l2 As Long
ActiveDocument.Repaginate
l1 = ActiveDocument.ComputeStatistics(wdStatisticPages)
doyourthing
l2 = ActiveDocument.ComputeStatistics(wdStatisticPages)
While l2 > l1
ActiveDocument.GoTo _
what:=wdGoToPage, _
which:=wdGoToAbsolute, _
Count:=l2
ActiveDocument.Bookmarks("\page").Range.Select
selection.Collapse
l1 = ActiveDocument.ComputeStatistics(wdStatisticPages)
doyourthing
l2 = ActiveDocument.ComputeStatistics(wdStatisticPages)
Wend
End Sub
' ------------------------------------
Sub doyourthing()
selection.TypeText Text:=String(10, Chr(13))
End Sub

Tough nut to break.

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

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

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