0
votes

I need to be able to find paragraphs that are wholly bold (such as a subheading), but I've been struggling to figure it out or find much help online. I've seen similar questions but the responses are too complicated for me to really know what I'm replicating, despite trying to use parts that seem relevant.

My end goal is to, after finding a wholly bold paragraph, delete the character immediately following it (usually an empty line).

So far, this is my code, using MsgBox as my quick easy test to see if the search works correctly:

Dim para As Paragraph

For Each para In ActiveDocument.Paragraphs
    If Selection.Font.Bond = True Then MsgBox "All Bold"
    Else: Next para

What this macro does is bring up a MsgBox saying "All Bold" for each paragraph in the document (as in, if there are 50 paragraphs it brings the MsgBox up 50 times), rather than check each paragraph then bring up a MsgBox IF it's entirely bold. Ideally, in my actual document of about 50 paragraphs, only the 3 headings would prompt the MsgBox to appear.

1
you are iterating all Paragraphs in para variable but in a loop you are not using paraPeter Ksenak

1 Answers

1
votes

As your code doesn't select anything Selection.Font.Bold does not relate to anything in the loop. By simply changing Selection to para.Range you will find only those paragraphs you are looking for.

Dim para As Paragraph

For Each para In ActiveDocument.Paragraphs
    If para.Range.Font.Bold = True Then para.Next.Range.Delete
Next para

The paragraph following can be accessed simply by using the Next property.

If the headings have been formatted using a style you could find them simply by looking for all instances of that style.