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

F

Freida

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?
 
G

Graham Mayor

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?

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


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
T

Tony Jollans

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
 
G

Graham Mayor

If the Heading, Vendor Name, and Vendor Address are each in separate
paragraphs Tony's macro will do that.

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


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Let me explain exactly what I am trying to accomplish, I have a
document that has several section breaks. basically one doc. for
several vendors so section 1 is going to be given to vendor A,
section 2 to Vendor B, and so on. At the Start of each section there
is a Header. Below the Header there is a the Vendor Name and
Address, which is consistent through out the document, and always in
the same position- <Header> (one return) <Vendor Name and Address>. I
want Vendor Name and Address Bolded.

I hope this message is more clear then the 1st one. I will try your
suggestion and any other Any suggestions will be greatly appreciated.
Thanks

Tony Jollans said:
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

--
Enjoy,
Tony

Freida said:
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?
 
H

Helmut Weber

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

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

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

Tony Jollans

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).
 

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