macro for de-bolding

B

BorisS

I need a macro that can go through a file and two things:

1) every paragraph that is ALL bold (when I select these types of lines,
they show up as totally bold) I need the macro to convert the paragraph
(which is actually an article title in each occurence in this document) to a
heading style. That way I can then create a table of contents easily.

2) every occurence of the word "the" in the article that is NOT in one of
these headings, I need the bold to be taken off (the word "the" on its own in
text in this article will always be bolded because of the way the document
generates).

Thanks.
 
B

BorisS

by they way, in this particular case, if it makes the macro easier, after the
headings are done, basically anything between two headings can be de-bolded,
so to speak. In other words, if the first step of the macro is to go through
and find all the headings and change the styles to headings, then if easier
to write, the next step of the macro could be to go between each two
occurences of a heading style, and take out bolding for all text in between.

Thx again to anyone that knows programming in Word well enough. I
unfortunately only know Excel well.
 
H

Helmut Weber

Hi Boris,

untested as I don't have sufficient testing material,
and only in principle, but seems sufficient.

Sub test5555()
Dim oPrg As Paragraph
For Each oPrg In ActiveDocument.Paragraphs
If oPrg.Range.Font.Bold = True Then
oPrg.Range.Select ' for testing
' apply heading style
MsgBox "all bold"
End If
Next
For Each oPrg In ActiveDocument.Paragraphs
If oPrg.Range.Font.Bold = 9999999 Then
oPrg.Range.Select ' for testing
MsgBox "some bold"
' set the ranges formatting to not bold
End If
Next
End Sub

Greetings from Bavaria, Germany
Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word 2002, Windows 2000
 
G

Greg

Boris,

Maybe something like:

Sub ScratchMacro()
Dim oPara As Paragraph
For Each oPara In ActiveDocument.Paragraphs
Select Case oPara.Range.Font.Bold
Case Is = True
oPara.Style = "Heading 1"
Case Is = wdUndefined
oPara.Range.Font.Bold = False
Case Else
oPara.Range.Font.Bold = False
End Select
Next
End Sub
 
B

BorisS

worked great. I wonder if you have anything to take care of the other
request of debolding all "the" occurences which are not part of the headings.
thx.
 
G

Greg

Boris,

Maybe I don't understand the issue completely, but I don't see how a
bold "the" can still be causing a problem. The code I sent you looks
at each complete paragraph. If all the text is bold then the text is
formatted with Heading 1 style. If part or none of the text is bold
then "bold" is set to off in all of the text. Are you still seeing
instances of "the" bolded by itself among other unbolded text?
 
B

BorisS

Greg, thanks so much. I am an idiot. I didn't even realize that the bolding
was off.
 

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