Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / July 2007

Tip: Looking for answers? Try searching our database.

Loop in macro

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Smudger Nowar - 19 Jul 2007 19:39 GMT
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
Russ - 21 Jul 2007 10:07 GMT
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

> Windows XP Pro; Word 2003
>
[quoted text clipped - 45 lines]
>
> http://www.myspace.com/billysolloxthespoonerrhythms

Signature

Russ

drsmN0SPAMikleAThotmailD0Tcom.INVALID

Curt - 31 Jul 2007 16:32 GMT
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

> Smudger,
> Your information is too vague.
[quoted text clipped - 73 lines]
> >
> > http://www.myspace.com/billysolloxthespoonerrhythms
Russ - 31 Jul 2007 19:02 GMT
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:
>>>>>Quote
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
>>>>>>UnQuote

> Thanks Russ
> Not sure of where to proceed but this sure gives me ideas. I am tring to set
[quoted text clipped - 79 lines]
>>>
>>> http://www.myspace.com/billysolloxthespoonerrhythms

Signature

Russ

drsmN0SPAMikleAThotmailD0Tcom.INVALID

Curt - 31 Jul 2007 19:40 GMT
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

> 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
[quoted text clipped - 103 lines]
> >>>
> >>> http://www.myspace.com/billysolloxthespoonerrhythms
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.