#1
|
|||
|
|||
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 |
#2
|
||||
|
||||
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
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#3
|
|||
|
|||
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.
|
#4
|
||||
|
||||
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] |
#5
|
|||
|
|||
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.
|
#6
|
|||
|
|||
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.
|
#7
|
||||
|
||||
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] |
#8
|
|||
|
|||
Thank you very much, now is okay.
|
Tags |
hide, macro, word2016 |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
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 |
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 |
document with 5 pages and a forward button | rich_cirillo | Word | 3 | 05-06-2014 06:16 PM |