Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Yes, this is possible. To make this work we have to use a combination of Word's inherent document protection, its hidden text attribute, and a couple of VBA tricks.</p> <p>First, format all the passwords in the document as hidden text. (For those who are unfamiliar, hidden text is only visible when the Show/Hide function is set to true.)</p> <p>Then add code to make sure that the hidden text will not display and also to protect the document from being edited whenever the document is opened:</p> <pre><code>Private Sub Document_Open() AddProtection End Sub Sub AddProtection() With ActiveDocument .ActiveWindow.View.ShowAll = False .ActiveWindow.View.ShowHiddenText = False .Application.Options.PrintHiddenText = False .Protect Type:=wdAllowOnlyReading, NoReset:=True, Password:="DesiredPassword" End With End Sub </code></pre> <p>Because Word users can normally display hidden text at any given time, we also need to take control of this function. Most menu and Ribbon commands can be intercepted by creating a module containing subroutines named for the intercepted commands. Naming a Sub <code>ShowAll</code> will allow us to control this function and only display hidden text when a password is entered:</p> <pre><code>Sub ShowAll() If ActiveDocument.ProtectionType = wdAllowOnlyReading Then 'Do nothing Else 'restore the Ribbon's toggle function If ActiveDocument.ActiveWindow.View.ShowAll = True Then ActiveDocument.ActiveWindow.View.ShowAll = False Else ActiveDocument.ActiveWindow.View.ShowAll = True End If End If End Sub </code></pre> <p>Finally, we add some code to prompt the user for a password and, if entered correctly, display the text that was formerly hidden:</p> <pre><code>Sub RemoveProtection() Dim strPassword As String strPassword = InputBox("Enter document password.") ActiveDocument.Unprotect Password:=strPassword If ActiveDocument.ProtectionType = wdNoProtection Then ActiveDocument.ActiveWindow.View.ShowHiddenText = True End If End Sub </code></pre> <p>Once all the VBA code is entered, right-click on the module in the IDE, select <strong>Project Properties</strong>, and assign a separate password on the Protection tab. This will stop power users from getting to the embedded password or changing the code.</p> <p>All that's left to do is create a QAT button in Word (that is only visible for this document) and assign the <code>RemoveProtection</code> sub to it. Whenever the document is opened the passwords will be hidden and protected from editing, but can then be revealed by clicking on the QAT button and entering the correct password.</p> <p><strong>EDIT</strong></p> <p>When I first answered this question, I failed to consider that Word has a hidden text option that can be turned on separateley from the Show All option. Additionally, hidden text can be printed via a printing option. I have added code in <code>AddProtection</code> above to turn off these settings.</p> <p>Further testing also revealed that a user in Word 2007 could manually go into <strong>Office Orb|Options|Display</strong> to reveal the hidden text by changing the <strong>Show all formatting marks</strong> or <strong>Hidden text</strong> options manually. To avoid this, a Ribbon customization would need to be created and loaded with the document.</p> <p>Finally, it is worth noting that although it is great fun to bend Word to one's will in order to make it accomplish tasks like this, the level of protection is not as good as encrypting the passwords separately and then unecrypting before revealing the contents or even using Word's document password feature to encrypt the document's entire contents.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload