Thread: [Solved] Unhide pages with button
View Single Post
 
Old 09-03-2018, 12:35 AM
macropod's Avatar
macropod macropod is offline Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,375
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Your code is unlikely to work well with tables, floating graphics and the like. Moreover, toggling the Font.Hidden property prevents neither the visibility nor the printing of the affected range; those are both things that depend on how the end-user has Word configured. You might do better to put the content to be conditionally-displayed inside an IF field linked to a numeric custom document property. The fields might be coded as:
{IF{DOCPROPERTY Section1}= 1 "Conditional Section1 content goes here"}
{IF{DOCPROPERTY Section2}= 1 "Conditional Section2 content goes here"}
{IF{DOCPROPERTY Section3}= 1 "Conditional Section3 content goes here"}
where Section# is the custom document property's name.

Note: The field brace pairs (i.e. '{ }') for the above examples are all created in the document itself, via Ctrl-F9 (Cmd-F9 on a Mac); you can't simply type them or copy & paste them from this message. Nor is it practical to add them via any of the standard Word dialogues. The spaces represented in the field constructions are all required.

You could then use a macro as simple as:
Code:
Private Sub section1_Click()
With ActiveDocument
  With .CustomDocumentProperties("Section1")
    .Value = (.Value + 1) Mod 2
  End With
  .Fields.Update
End With
End Sub
to toggle the display for Section1 on/off.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote