0
votes

My Google-fu must be very weak today, ’cause this seems like an obvious thing to need to do sometimes, yet I cannot find a single case of anyone ever asking about it anywhere…

I have a document that I am preparing for proper typesetting in InDesign, which includes among other things getting rid of local overrides to paragraph and character styles. I did an find-and-replace to replace all instances of italic text with a character style called Italic, but stupidly forgot to limit this to text with the Normal style applied.

There are hundreds of headers strewn throughout the document which are supposed to be italic; that’s part of their paragraph style definitions. Since I forgot to limit the find-and-replace, the Italic style was applied to all these many headers. Annoyingly, since ‘italic’ is something like a boolean switch in Word, this means that all these headers are now not italic in the document.

I didn’t notice this for a while, so I can’t simply undo it now—the file has been saved and worked on since the find-and-replace. The author (who is a cantankerous, octogenarian technophobe) also needs to see the file again before it’s set, so while ultimately it doesn’t matter whether or not the font is italic in the Word document, it will matter to him.

So what I would very much like to do is to search for all text which has both the paragraph style Header and the character style Italic applied, and remove the character style.

This is an easy task in InDesign where paragraph and character styles are separate entities, but not in Word where they’re all lumped together in one big, messy pile. It doesn’t seem like it can be done through the UI, so I’m guessing I’ll have to resort to a VBA macro… which I’m utterly incompetent at.

Is there a way to find text with a particular paragraph style and a particular character style, and then remove the character style from that text?

1

1 Answers

0
votes

here is some code to get you started

press F5 to run code, it will stop at Stop command

examine the Immediate window to determine the header style

each paragraph gets selected, so that you can tell which one you are examining

you can then modify the code with if/then statement to make specific paragraphs italic

Sub aaaa()

    Dim ppp As Paragraph
    Dim ccc As Range

    For Each ppp In ActiveDocument.Content.Paragraphs

        ppp.Range.Select           ' visual aid only. not used by any other part of the program

        Debug.Print "style :", ppp.Style
        Debug.Print ppp.Style.Description

Stop

        For Each ccc In ppp.Range.Characters       ' you can probably comment out these 3 lines
            Debug.Print ccc.FormattedText.Italic   ' True prints as -1
        Next ccc

        Debug.Print "italic :", ppp.Range.Italic   ' prints -1 if all are italic. 9999999 if some. 0 if none
        ppp.Range.Italic = False                   ' this removes italic from whole paragraph

    Next ppp

End Sub