#1
|
|||
|
|||
Conditionally hiding parts of a document
I have a similiar problem using Word 2010 to the one described in: https://www.msofficeforums.com/word-...html#post61030.
I have a document that has multiple macrobuttons located throughout the document to control whether certain text is displayed or hidden. The macrobutton basically calls a bookmark, and based on the macrobutton parameter either displays or hides the bookmarked text. Is there a way to modify the Sub FilePrint() so all the macrobuttons do not print? I need to be able to preview the print without the macrobuttons if possible. I have applied your code, and yes, the first macrobutton is not printed. I just need to be able to replicate that throughout the document. Thank you for your time. |
#2
|
||||
|
||||
For that you could use code like:
Code:
Sub FilePrint() Application.ScreenUpdating = False Dim oFld As Field, Rng As Range With ActiveDocument .ActiveWindow.View.ShowFieldCodes = False For Each oFld In .Fields With oFld If .Type = wdFieldMacroButton Then .Code.Font.Hidden = True .Update End If End With Next Application.Dialogs(wdDialogFilePrint).Show For Each oFld In .Fields With oFld If .Code.Font.Hidden = True Then .Code.Font.Hidden = False .Update End If End With Next End With Application.ScreenUpdating = True End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#3
|
|||
|
|||
Thank you for your suggestion. I guess this application is a little more complicated when I implement the code. I am attaching a pdf that show the code works for the printout. I would like to send you two docm files, the first would be the document I printed, and the second would be the document after the screen updates were made. Since I can't upload these files here, how can I send them to you? I have created them as trusted douments, with the macros they use contained in them.
My users will have the option to collapse any portion or portions of the document as they are editing it. The samples I would like to send you shows what the document looks like before I print it, and the second file is the results with the screen updates from printing after I selected to collape all the "metadata" entries within the document. New thought: Would it be possible to create a temp copy of the document for printing? Once the doc is printed, this temp could be deleted, leaving the original document in tack. This is what is happening: I have selected to hide mulitple sections of the document which contain macrobuttons. When the file gets updated via the screen update, any macrobutton that was hidden at prnt time is coming back with the macrobutton expanded code (MACROBUTTON PS_1_1_1_Metadata Collapse). I cannot toggle it back to the "button". Any macrobutton that was not hidden before the PrintPreviewAndPrint macro is executed, is replaced correctly via the screen update (Collapse-Section_1). This is the code that is setup for each "section/subsection" of my document: Code:
Sub PS_1_1_Metadata() ActiveWindow.View.ShowHiddenText = False With Selection.Fields(1).Code If InStr(.Text, "Collapse") > 0 Then .Text = Replace(.Text, "Collapse", "Expand") ActiveDocument.Bookmarks("PS_1_1_Metadata").Range.Font.Hidden = True Else .Text = Replace(.Text, "Expand", "Collapse") ActiveDocument.Bookmarks("PS_1_1_Metadata").Range.Font.Hidden = False End If End With End Sub Each macrobutton has a corresponding bookmark which indicates which text is being displayed or hidden. The doc looks similar to the following: bookmark Section_1_Button macrobutton: Collapse-Section_1 End of bookmark 1. Section 1 paragraph Bookmark: PS_Section_1_Subsections bookmark: PS_1_Button macrobutton: Collapse End of bookmark bookmark: PS_1_Metadata Metadata 1 Table appears here End of bookmark 1.1 Section 1 paragraph bookmark: PS_1_1_Button macrobutton: Collapse End of bookmark bookmark: PS_1_1_Metadata Metadata 1.1 Table appears here End of bookmark PS_1_1_Metadata End of bookmark PS_Section_1_subsections The macrobuttons and bookmarks nest throughout the document. I can select to hide (or restore) via macrobutton Collapse or Expand options: · Everything except the first level Section paragraphs · The Metadata throughout the entire document · An individual section · Each individual metadata sections This setup allows the users to save the document in any state of collapsed or expanded sections. Two items are still needed to make this efficient: A macro that would “read” the “saved options” for the macrobuttons, and execute that option when the document is opened. A way to “reset” all the macrobuttons to Collapse as an option. I don’t want to do the reset automatically when the doc opens, because the user may want the document to open with the options specified as they saved it. Last edited by macropod; 03-21-2014 at 02:06 PM. Reason: Added code tags & formatting |
#4
|
||||
|
||||
Hi glowackt,
Your issues are quite different from those described in the original thread, so I've separated this discussion into a new thread. It seems you don't necessarily want to hide the macrobuttons at print time (not sure about this) but that you want to use them to conditionally hide/show content in certain ranges. I must say at the outset that I don't see that what you're trying to do is worth the effort, given that: Word's outline view can be used to expand/collapse the document; a Table of Contents to quickly navigate to areas of interest; and the document window can be split to allow different areas to be viewed at the same time. I note you're using bookmarks to identify the ranges to be expanded/collapsed. I'd suggest using Section breaks instead, as bookmarks are quite fragile, in addition to which it's easy to unintentionally insert content outside a bookmarked range. With a little forethought, this would also mean you could use a single show/hide macro for all the macrobutton fields. As for reading the 'saved' options for the macrobutton fields, the simplest way is to save the document with the show/hide state the user had in place; otherwise you'd need an elaborate set of document properties/variables that would be read and processed when the document is opened, alongside also ensuring the document can't be saved in any state other than what you want. Since the outcome would be the same in terms of what is seen when the document is opened, nothing is achieved for all that circumlocution. A macro to unhide all the document content is trivial: Code:
Sub Unhide() ActiveDocument.Range.Font.Hidden = False End Sub PPS: You can attach docm files by adding them to a zip archive beforehand, then attaching that.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#5
|
|||
|
|||
I am attaching some files that may help describe what we are trying to do.
The original file is: Doc format - metadata collapsed - tracked changes - original.docm I had it collapsed or expanded when I printed both of the following files: Doc format - metadata collapsed - tracked changes.pdf Doc format - metadata collapsed - tracked changes - printed via macros.pdf The “Doc format - metadata collapsed - tracked changes.pdf” file shows how I had the original document marked up when I went to print. The “Doc format - metadata collapsed - tracked changes - printed via macros.pdf” file shows the macrobuttons no longer exist in the printed version, which is what I want. The second version of that code worked wonderfully. Thank you. What happens now, is when I re-open the “Doc format - metadata collapsed - tracked changes - original.docm” file, it has “Expand” sections indicated in the macrobuttons, but the text within the bookmark is actually expanding. This is where I would like the macrobutton to be able to interrupt correctly what was saved, and hide the text within the bookmark as requested. These documents may be edited multiple times, before they are ready for review. I would like to have a macrobutton called “reset” that would go through the entire document and “reset” all the macrobuttons to “Collapse”, when the document editor selected that particular macrobutton. I have chosen to use bookmarks, because I plan to export the bookmarks, and integrate the exported values for each document into a database. There are a whole series of documents like this that we need to be able to track within a database. I have tried to create the bookmarks so they are "out of the way" for most of the areas that will worked by the editor/reviewer. The final deliverable document (pdf), will not include any of the macrobuttons or attribute data that is enclosed within the bookmarks. I really appreciate your time and talent. |
#6
|
||||
|
||||
You can probably achieve what you're after with:
Code:
Sub FilePrint() Application.ScreenUpdating = False Dim i As Long, Rng As Range With ActiveDocument .ActiveWindow.View.ShowFieldCodes = False For i = .Fields.Count To 1 Step -1 With .Fields(i) If .Type = wdFieldMacroButton Then .Code.Font.Hidden = True .Update End If End With Next Application.Dialogs(wdDialogFilePrint).Show For i = .Fields.Count To 1 Step -1 With .Fields(i) If .Code.Font.Hidden = True Then .Code.Font.Hidden = False .Update End If If .Type = wdFieldMacroButton Then .DoClick: .DoClick End With Next End With Application.ScreenUpdating = True End Sub Code:
Sub PS_Requirements() ActiveWindow.View.ShowHiddenText = False Dim i As Long, ArrBkMk ArrBkMk = Array("PS_All_Metadata", "PS_1_ReqtTextOnly", "PS_1_Sec_Button", _ "PS_1_Button", "PS_2_ReqtTextOnly", "PS_2_Sec_Button", "PS_2_Button", _ "PS_3_ReqtTextOnly", "PS_3_Sec_Button", "PS_3_Button", "PS_4_ReqtTextOnly", _ "PS_4_Sec_Button", "PS_4_Button", "PS_5_ReqtTextOnly", "PS_5_Sec_Button", _ "PS_5_Button", "PS_6_ReqtTextOnly", "PS_6_Sec_Button", "PS_6_Button", _ "PS_7_ReqtTextOnly", "PS_7_Sec_Button", "PS_7_Button", "PS_8_ReqtTextOnly", _ "PS_8_Sec_Button", "PS_8_Button", "PS_9_ReqtTextOnly", "PS_9_Sec_Button", _ "PS_9_Button", "PS_10_ReqtTextOnly", "PS_10_Sec_Button", "PS_10_Button", _ "PS_11_ReqtTextOnly", "PS_11_Sec_Button", "PS_11_Button", _ "PS_12_ReqtTextOnly", "PS_12_Sec_Button", "PS_12_Button") With Selection.Fields(1).Code If InStr(.Text, "Collapse") > 0 Then .Text = Replace(.Text, "Collapse", "Expand") With ActiveDocument For i = 0 To UBound(ArrBkMk) .Bookmarks(ArrBkMk(i)).Range.Font.Hidden = True Next End With Else .Text = Replace(.Text, "Expand", "Collapse") With ActiveDocument For i = 0 To UBound(ArrBkMk) .Bookmarks(ArrBkMk(i)).Range.Font.Hidden = False Next End With End If End With End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#7
|
|||
|
|||
Any chance you have these MS word files you might be able to forward on to me. I really would like to implement this and haven't found a described solution anywhere yet.
thanks |
#8
|
||||
|
||||
Did you look at the attachments to post #3?
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#9
|
|||
|
|||
that is just a PDF file. I'm looking for the word file with the actual code the OP mentioned in post 3
|
#10
|
||||
|
||||
Did you look in the zip file???
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Moving Quick Parts with the document | derohanes | Word | 4 | 10-23-2013 09:30 PM |
Print only certain parts of a document on demand | jirkap | Word VBA | 1 | 09-29-2013 08:56 PM |
Creating new document from parts of another document | matthewgeary | Word VBA | 1 | 10-05-2012 10:09 AM |
hiding images in word document | gib65 | Drawing and Graphics | 3 | 08-17-2011 11:09 AM |
hiding selected objects in word document | gib65 | Word | 0 | 08-09-2011 12:00 PM |