Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 08-31-2018, 05:51 AM
dadam dadam is offline Unhide pages with button Windows 10 Unhide pages with button Office 2016
Novice
Unhide pages with button
 
Join Date: Aug 2018
Posts: 4
dadam is on a distinguished road
Default Unhide pages with button

Hi, I'd like to hide/unhide pages with buttons. I have 3 section. Every section is 10-15 pages with text, tables and a picture. Has a max page or character limit? If I use the macro with half or one page, everything is fine, but if I make a bookmark from all of 10 pages, it doesn't work anymore. Edit1: I try it with 50 pages, just text and no problem. What can be the problem? The tables?

My macro for first section:



Private Sub section1_Click()
If Bookmarks("bm1").Range.Font.Hidden = False Then
Bookmarks("bm1").Range.Font.Hidden = True
Else
Bookmarks("bm1").Range.Font.Hidden = False
End If
End Sub
Reply With Quote
  #2  
Old 09-03-2018, 12:35 AM
macropod's Avatar
macropod macropod is offline Unhide pages with button Windows 7 64bit Unhide pages with button Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
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
  #3  
Old 09-05-2018, 02:00 AM
dadam dadam is offline Unhide pages with button Windows 10 Unhide pages with button Office 2016
Novice
Unhide pages with button
 
Join Date: Aug 2018
Posts: 4
dadam is on a distinguished road
Default

Something not work for me, always have an error with properties. Can you show me on this document with 1 section? Maybe if I see it on the document I can do it later.
Attached Files
File Type: docm probe3.docm (97.4 KB, 12 views)
Reply With Quote
  #4  
Old 09-05-2018, 02:06 AM
macropod's Avatar
macropod macropod is offline Unhide pages with button Windows 7 64bit Unhide pages with button Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
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

I can't see any field coding of the kind I described, custom document properties of the kind I described, or macro code in your attachment. It's a bit hard to diagnose anything in such a situation...
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #5  
Old 09-05-2018, 07:04 AM
dadam dadam is offline Unhide pages with button Windows 10 Unhide pages with button Office 2016
Novice
Unhide pages with button
 
Join Date: Aug 2018
Posts: 4
dadam is on a distinguished road
Default

Oh, sorry. I attached the wrong document. Now it's okay. I think it's a very big failure what I did, never work with IF before. I found some blog about it, but can't help for me.
Attached Files
File Type: docm probe3.docm (103.1 KB, 12 views)
Reply With Quote
  #6  
Old 09-05-2018, 01:15 PM
slaycock slaycock is offline Unhide pages with button Windows 7 64bit Unhide pages with button Office 2016
Expert
 
Join Date: Sep 2013
Posts: 256
slaycock is on a distinguished road
Default

An alternative approach would be to split your document into smaller documents which represent the sets of pages you want to show or hide. You can then build your main document as a series if include fields nested within if fields.
Reply With Quote
  #7  
Old 09-05-2018, 02:40 PM
macropod's Avatar
macropod macropod is offline Unhide pages with button Windows 7 64bit Unhide pages with button Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
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

dadam: Your attachment is still missing the custom document property named 'Section1'. Add that (via File>Properties>Advanced Properties>Custom) and the document will work as intended.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #8  
Old 09-06-2018, 12:41 AM
dadam dadam is offline Unhide pages with button Windows 10 Unhide pages with button Office 2016
Novice
Unhide pages with button
 
Join Date: Aug 2018
Posts: 4
dadam is on a distinguished road
Default

Quote:
Originally Posted by macropod View Post
dadam: Your attachment is still missing the custom document property named 'Section1'. Add that (via File>Properties>Advanced Properties>Custom) and the document will work as intended.
Thank you very much, now is okay.
Reply With Quote
Reply

Tags
hide, macro, word2016



Similar Threads
Thread Thread Starter Forum Replies Last Post
Unhide pages with button Print only specified pages of word by 1 click of command button using vba Zhibek Word VBA 9 08-12-2018 11:44 PM
Cannot unhide rows in VBA RosieSummers Excel Programming 2 02-12-2018 12:47 AM
Unhide pages with button Button within Word to print certain pages hotcomper Word 1 08-10-2015 11:36 PM
A row that will not UNHIDE MaineLady Excel 0 11-23-2014 01:15 PM
Unhide pages with button document with 5 pages and a forward button rich_cirillo Word 3 05-06-2014 06:16 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 01:18 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft