Hidding test based on style

T

Tony Starr

Some time ago the following code was posted to this newsgroup as a way to
hide/display text based on its style.

Sub ShowMessages()
With ActiveDocument
.Styles("Message").Font.Hidden = False
.Styles("Summary").Font.Hidden = True
End With
End Sub


Sub ShowSummaries()
With ActiveDocument
.Styles("Message").Font.Hidden = True
.Styles("Summary").Font.Hidden = False
End With
End Sub


Sub ToggleMessages()
With ActiveDocument
If .Styles("Summary").Font.Hidden = False Then
.Styles("Message").Font.Hidden = False
.Styles("Summary").Font.Hidden = True
Else
.Styles("Message").Font.Hidden = True
.Styles("Summary").Font.Hidden = False
End If
End With
End Sub

I have created a document (attached) that has lines of text that are
alternately formatted using Summary Style or Message Style.
I find that the ShowMessages macro hides all text regardless of style and
ShowSummaries shows all rext regardless of style.
I feel I am doing something fundamentally wrong. Can you offer any
assistance?

Many Thanks
Tony Starr


PS. I am using Word xp
 
K

Klaus Linke

Hi Tony,

The attachment didn't make it to the MS news server, but it seems likely
that your "Message" style is based on the "Summary" style?

Regards,
Klaus
 
K

Klaus Linke

Hi Tony,
I have included the attachment this time but without any macros in it.
I don't think that my message style is based on my summary style but I
might be wrong.

You had applied "hidden" as manual formatting on top of the "Message"
paragraphs.
The style itself was defined as "hidden", so "hidden+hidden=not hidden".

If you remove the manual formatting (Ctrl+A, Ctrl+Spacebar), the macros
should work.
Could you please also explain to me why the following statements when run
in the immediate window only hide the text formatted with the summary
style

activedocument.sections(2).range.font.Hidden = True

and

activedocument.bookmarks("mAllText").Range.Font.Hidden = True

Same reason: The two lines of code both apply "hidden" as manual formatting,
and since the "Message" style is already defined as "hidden", you get "not
hidden".

If you try to avoid manual formatting -- and do the toggling of style
visibility only through the style definitions -- you shouldn't run into
problems.

Good luck!
Klaus
 

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