Hauke
Hauke

Reputation: 1465

Word 2007 password protection for single words

is it possible to put a password on a single word inside a word document?

What I want is to write a system documentation from our IT structure. I want to put the passwords in the document as well. Now I want that you have to enter a "MASTER" password in order to unlock to passwords inside the document. If you do not enter the password, the passwords inside the document should be invisible or something like that.

Is that possible?

Upvotes: 0

Views: 592

Answers (1)

joeschwa
joeschwa

Reputation: 3175

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.

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.)

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:

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

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 ShowAll will allow us to control this function and only display hidden text when a password is entered:

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

Finally, we add some code to prompt the user for a password and, if entered correctly, display the text that was formerly hidden:

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

Once all the VBA code is entered, right-click on the module in the IDE, select Project Properties, and assign a separate password on the Protection tab. This will stop power users from getting to the embedded password or changing the code.

All that's left to do is create a QAT button in Word (that is only visible for this document) and assign the RemoveProtection 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.

EDIT

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 AddProtection above to turn off these settings.

Further testing also revealed that a user in Word 2007 could manually go into Office Orb|Options|Display to reveal the hidden text by changing the Show all formatting marks or Hidden text options manually. To avoid this, a Ribbon customization would need to be created and loaded with the document.

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.

Upvotes: 1

Related Questions