Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 03-20-2014, 09:24 AM
glowackt glowackt is offline Conditionally hiding parts of a document Windows 7 64bit Conditionally hiding parts of a document Office 2010 32bit
Novice
Conditionally hiding parts of a document
 
Join Date: Mar 2014
Posts: 3
glowackt is on a distinguished road
Default 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.
Reply With Quote
  #2  
Old 03-20-2014, 02:38 PM
macropod's Avatar
macropod macropod is offline Conditionally hiding parts of a document Windows 7 32bit Conditionally hiding parts of a document Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
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

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]
Reply With Quote
  #3  
Old 03-21-2014, 09:03 AM
glowackt glowackt is offline Conditionally hiding parts of a document Windows 7 64bit Conditionally hiding parts of a document Office 2010 32bit
Novice
Conditionally hiding parts of a document
 
Join Date: Mar 2014
Posts: 3
glowackt is on a distinguished road
Default

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
Reply With Quote
  #4  
Old 03-21-2014, 02:31 PM
macropod's Avatar
macropod macropod is offline Conditionally hiding parts of a document Windows 7 32bit Conditionally hiding parts of a document Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
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

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
PS: When posting code, please use the code tags. They're on the 'Go Advanced' tab.
PPS: You can attach docm files by adding them to a zip archive beforehand, then attaching that.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #5  
Old 03-24-2014, 09:32 AM
glowackt glowackt is offline Conditionally hiding parts of a document Windows 7 64bit Conditionally hiding parts of a document Office 2010 32bit
Novice
Conditionally hiding parts of a document
 
Join Date: Mar 2014
Posts: 3
glowackt is on a distinguished road
Default

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.
Reply With Quote
  #6  
Old 03-24-2014, 03:26 PM
macropod's Avatar
macropod macropod is offline Conditionally hiding parts of a document Windows 7 32bit Conditionally hiding parts of a document Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
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

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
Note: Instead of those many lines of 'ActiveDocument.Bookmarks(name).Range.Font.Hidden =' in your 'PS_Requirements' and 'PS_All_Metadata' subs you could simplify the code with arrays and loops like:
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]
Reply With Quote
  #7  
Old 05-16-2017, 09:55 AM
nathan.gray@emerson.com nathan.gray@emerson.com is offline Conditionally hiding parts of a document Windows 7 64bit Conditionally hiding parts of a document Office 2016
Novice
 
Join Date: May 2017
Posts: 6
nathan.gray@emerson.com is on a distinguished road
Default

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
Reply With Quote
  #8  
Old 05-16-2017, 04:40 PM
macropod's Avatar
macropod macropod is offline Conditionally hiding parts of a document Windows 7 64bit Conditionally hiding parts of a document Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
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

Quote:
Originally Posted by nathan.gray@emerson.com View Post
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.
Did you look at the attachments to post #3?
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #9  
Old 05-16-2017, 07:17 PM
nathan.gray@emerson.com nathan.gray@emerson.com is offline Conditionally hiding parts of a document Windows 7 64bit Conditionally hiding parts of a document Office 2016
Novice
 
Join Date: May 2017
Posts: 6
nathan.gray@emerson.com is on a distinguished road
Default

that is just a PDF file. I'm looking for the word file with the actual code the OP mentioned in post 3
Reply With Quote
  #10  
Old 05-16-2017, 07:18 PM
macropod's Avatar
macropod macropod is offline Conditionally hiding parts of a document Windows 7 64bit Conditionally hiding parts of a document Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
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

Did you look in the zip file???
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Moving Quick Parts with the document derohanes Word 4 10-23-2013 09:30 PM
Conditionally hiding parts of a document Print only certain parts of a document on demand jirkap Word VBA 1 09-29-2013 08:56 PM
Conditionally hiding parts of a document 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

Other Forums: Access Forums

All times are GMT -7. The time now is 11:36 AM.


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