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 / January 2007

Tip: Looking for answers? Try searching our database.

writing a Macro to format the 1st 3 lines of each section

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Freida - 12 Jan 2007 12:42 GMT
I have a document with several sections in it.  Is it possible for me to
write a macro that bolds the first 3 lines of each section?
Graham Mayor - 12 Jan 2007 14:15 GMT
There is no 'line' as such in Word. A 'line' of text is a transient item
determined by the size of the font, the distance between the margins and the
current printer driver, so what is it *exactly* you wish to embolden.
Do these three 'lines' constitute a complete paragraph or paragraphs - or
only part of a paragraph?
What do you expect to happen when emboldening the three 'lines' increases
the amount of space the text occupies forcing some of the words onto the
next 'line' - which it almost certainly will?

Signature

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor -  Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

> I have a document with several sections in it.  Is it possible for me
> to write a macro that bolds the first 3 lines of each section?
Tony Jollans - 12 Jan 2007 14:16 GMT
Yes, if you define what you mean by "line". Lines are printer-dependent and
are not necessarily always the same unless you have explicitly delimited
them.  If you really mean paragraphs, here is one way:

For Each Sect In ActiveDocument.Sections
   With Sect.Range.Find
       .Text = "[!^13]@^13[!^13]@^13[!^13]@^13"
       .Replacement.Font.Bold = True
       .MatchWildcards = True
       .Execute Replace:=wdReplaceOne
   End With
Next

Signature

Enjoy,
Tony

>I have a document with several sections in it.  Is it possible for me to
> write a macro that bolds the first 3 lines of each section?
Helmut Weber - 12 Jan 2007 23:11 GMT
Hi Tony,

originally, I wanted to check, whether your macro bolds
the section break character, too.
Never mind, it isn't that important.

But then, using a rather simple doc of 9 pages, I get,

first:
Run-time error 5226: The document is too large for Word to handle.
or
command failed
pointing to this line: .Execute Replace:=wdReplaceOne

Next:
The document is too large too save.

Next:
Run-time error: -2147417848
The object invoked has disconnected from its clients.

Next:
Word doesn't respond anymore: CPU > 95 percent.

Just another corrupted doc, or what?

At least, this is reproducable.

I've sent you a copy.

Any ideas?

Happy thinking

Signature

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

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

Tony Jollans - 13 Jan 2007 23:23 GMT
Hi Helmut,

This is a bug in F&R - with somewhat exaggerated effect.

When the text which ought to be found by a wildcard search contains a Field,
F&R doesn't work properly. You have a hyperlink in the third paragraph of
the matched text in section 1 (actually the fourth paragraph but my sloppy
code ignores empty paragraphs).

Signature

Enjoy,
Tony

> Hi Tony,
>
[quoted text clipped - 29 lines]
>
> Happy thinking
 
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.