Hiding text based on custom document property

K

kbutterly

Good afternoon, all,

I am trying to show/hide text based on a custom document property,
Audience. When my document opens, a form appears with three options,
All, Agency, and Program Office.

Here is the code behind the form button's onClick event:

Private Sub cmdOpen_Click()
Dim st As style

If Me.Controls("optAll").Value Then
ActiveDocument.CustomDocumentProperties("Audience").Value = "All"
ElseIf Me.Controls("optAgency").Value Then
ActiveDocument.CustomDocumentProperties("Audience").Value =
"Agency"
Else
ActiveDocument.CustomDocumentProperties("Audience").Value =
"ProgramOffice"
End If


If Me.Controls("optAll").Value Then
For Each st In ActiveDocument.Styles
If InStr(st.NameLocal, "Agency") > 0 Then
st.Font.Color = wdColorBrightGreen
st.Font.Hidden = False
ElseIf InStr(st.NameLocal, "ProgramOffice") > 0 Then
st.Font.Color = wdColorRed
st.Font.Hidden = False
End If
Next
Else
For Each st In ActiveDocument.Styles
st.Font.Color = wdColorAutomatic
If InStr(st.NameLocal, "Agency") > 0 Then
st.Font.Hidden = Not Me.Controls("optAgency").Value
ElseIf InStr(st.NameLocal, "ProgramOffice") > 0 Then
st.Font.Hidden = Not Me.Controls("optProgramOffice").Value
End If
Next st
End If

ActiveWindow.View.ShowHiddenText = False

frmAudience.hide

End Sub

So...first I set the custom document property.

If the user chooses the option labelled All (which I would do when I am
creating this manual) I want to show all styles, with any style
containing the word 'Agency' in its name showing as bright green text
and any style with ProgramOffice showing as red.

If the user choosed the option labelled "Agency" I want only the styles
containing 'Agency' to show, and have all styles containing
'ProgramOffice' to be hidden. So, I set the Hidden property of all the
styles containing Agency to the opposite of the option control. In
other words, if Agency was selected, then
Me.Controls("optAgency").Value will be true, and I want the font for
the styles containing 'Agency' to have a hidden property of false.

The problem is that after running the lines that assign the value to
st.Font.hidden, st.Font.hidden equals -1. I found one posting that I
didn't really understand, but it seemed to say that this was because
the style was a paragraph style.

So, can I do what I want? If so, what am I missing?

Any ideas, resources, references would be greatly appreciated.

Thanks,
Kathryn
 
K

kbutterly

Never mind...the code as posted is now working fine...hmmm...methinks
there are gremlins...

thanks anyway,
Kathryn
 

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