Macro to change style of Heading 2 to hidden fails on CharHidden

Here’s the macro. Why doesn’t it work? A nearly identical macro using textbod works well.

Sub ToggleHeading2

oStyleFam = ThisComponent.StyleFamilies

ParaStyles =oStyleFam.getByName(“ParagraphStyles”)

Heading2 = ParaStyles.getByName(“Heading 2”)

If Heading2.CharHidden = True Then

Heading2.CharHidden = False

Else

Heading2.CharHidden = True

End If

End Sub

Very strange. The macro is working properly. Only, perhaps, should be replaced if-then-else on one line Heading2.CharHidden = not Heading2.CharHidden

Very, very strange. Your macro is more elegant than mine but produces the same error for me. And you say my macro works on your machine? (And a nearly identical macro works on my machine using TextBod instead of Heading2.) I have a macro poltergeist. It says that the first CharHidden is wrong.

On first start I also thought that the macro has not done anything. It just underline (dots) the text with style Header 2 . Then I realized that I did not turn off the display of non-printing characters… Oops!.. :wink:

Please try this - testOfMacro.odt

Your file’s button did not work for me.
???
However, on my document I deleted all three modules I’d been testing, and re-entered them using your code, and leaving the names as Module 1, Module 2, and so on, and letting the command name itself from the code.
And then I re-tested, and they work ??
Then I tried my code, and that seems to work also, provided I deleted the modules and created new ones.
???
I want to thank you for your help on behalf of myself and 25 romance novelists from New Hampshire.
Susan Cragin