Loop in macro

S

Smudger Nowar

Windows XP Pro; Word 2003

I have a macro that starts with a basic text document and formats it
by inserting new lines and at a point where it finds some particular
text (Let's call it "This is the heading") it inserts a page break.

The initial text document can be anything from 1 to 400 pages long, so
I need something to get it to repeat the bit from the top of the page,
to the bit where it inserts the page break.

I've done similar in XL, using code like:- Do While activecell <>
####, but cannot work out how to do it in Word (I HVAE looked,
honest).

My code is something like this

Formats page 1, inserting some lines, generally making look good.

at certain text at bottom of page 1, inserts a page break.

On page 2 (this is where it needs to loop from), centres the first
three lines

inserts some blank lines,

formats some text

at certain text at bottom of page 2, inserts a page break.

so it should loop from "On page2" to inserting the page break at the
foot of page2 and go on until the end of the document.

Any help much appreciated.

TIA

Steve



Regards


Smudger


Check out the anti-war songs at:-

http://www.billysollox.com

http://www.soundclick.com/billysolloxandthespoonerrhythms

http://www.myspace.com/billysolloxthespoonerrhythms
 
R

Russ

Smudger,
Your information is too vague.

This Code will loop through every instance of (Let's call it "This is the
heading") until the end of the document.
You can record a macro while doing the other stuff you require and
you can try putting your code inside this piece of code:
Run it first, by itself to see if it selects what you want.

Dim aRange As Range
Dim aRange2 As Range
Set aRange = ActiveDocument.Content
With aRange.Find
.Text = "(Let's call it "This is the heading")"
While .Execute = True
aRange2 = aRange.Duplicate


aRange2.select
'delete or comment out line below after testing
MsgBox "Check this out."

'Your code here:



Wend
End With
End Sub
 
C

Curt

Thanks Russ
Not sure of where to proceed but this sure gives me ideas. I am tring to set
page breaks in excel based on size of cells in column (M) yore code her is a
start
Thanks
 
R

Russ

Headings mean a different thing in Word, usually; unless you make it clear
that you are talking about a heading row in a table, most Word users will
think you are talking about a style applied to a paragraph to make it stand
out from the other paragraphs. Are you talking about searching for a style
outside of a table? The find function in Word can search for styles, too.

In case you are trying to reinvent the wheel.
This is from Word Help:Repeat a table heading on subsequent pages
1. Select the row or rows of text that you want to use as a table heading.
The selection must include the first row of the table.
2. On the Table menu, click Heading Rows Repeat.
Notes
€ Microsoft Word automatically repeats table headings on new pages that
result from automatic page breaks. Word does not repeat a heading if you
insert a manual page break within a table.
€ Repeated table headings are visible only in page layout view or when you
print the document.
See also
Break a table across pages
About tables
 
C

Curt

Thanks for the heads up Am learning about the difference. downloaded a MVP
getting grips on VBA. doing it in word works When trying same in excel the
references shown in word are not shown in excel. Do you know if the same is
possible. This down load for word is very helpful.
Thanks for help
 

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