Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / August 2006

Tip: Looking for answers? Try searching our database.

Hiding text based on custom document property

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
kbutterly@yahoo.com - 08 Aug 2006 19:10 GMT
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
kbutterly@yahoo.com - 08 Aug 2006 19:24 GMT
Never mind...the code as posted is now working fine...hmmm...methinks
there are gremlins...

thanks anyway,
Kathryn

> Good afternoon, all,
>
[quoted text clipped - 70 lines]
> Thanks,
> Kathryn
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.