Office documents may not look like privacy nightmares, but many of them are actually riddled with data that can unwittingly disclose information about you, other people who have used the document, file locations, email addresses, and much more. This type of information is known as metadata, and if you're even slightly concerned about maintaining your privacy, you should take steps to minimize or remove metadata. That's not to say that metadata is always evil. Much metadata is generated by the collaboration techniques you learned about in Chapter 7, "Working as a Team: Collaborating with Other Users" and Chapter 9, "Collaborating with a Tablet PC and OneNote." Tracked changes, comments, and annotations all generate metadata about the reviewers, which is truly useful in a collaborative environment. However, after the document is finished, all that metadata is no longer required; and if you'll be publishing the document, the metadata is a serious privacy concern, as well. The next three sections show you how to eliminate metadata as much as possible in your Office documents. Setting Document Privacy OptionsWord, Excel, PowerPoint, and Publisher all contain an option that automatically eliminates much metadataincluding the document author, track changes authors, and comment authorseach time you save a document. Follow these steps to activate this option:
Note that Word's Security tab also contains the following privacy options:
Using the Remove Hidden Data ToolWord, Excel, and PowerPoint documents actually have a lot more privacy problems than simply the personal information of the document authors and editors. Document versions, routing slips, Excel scenario comments, and even recorded VBA macro descriptions (which include your name) are all potential privacy problems. All these items can be scrubbed from a document by hand, but Microsoft has given us an easier method: an Office add-in called the Remove Hidden Data tool, which you can download here: http://www.microsoft.com/downloads/details.aspx?FamilyID=144e54ed-d43e-42ca-bc7b-5446d34e5360 This add-in enhances privacy by automating the removal of the following document data:
After you install the Remove Hidden Data tool, follow these steps to use it on a document:
Removing Other Private DataThe Remove Hidden Data add-in does a good job of removing the major sources of private data, but it doesn't get them all. The next few sections take you through a few other potential sources of privacy breaches. Removing Hidden TextIf you use hidden text in a Word document to store sensitive information, you need to be sure to delete that text before publishing the document. One way to do this is to display hidden text (select Tools, Options, select the View tab, and activate the Hidden Text check box) and then use the Find feature to locate text where the font is formatted as hidden. You could also use a VBA macro like the one shown in Listing 14.1.
Listing 14.1. A Procedure That Finds the Hidden Text in the Active Document and Prompts to Delete ItSub RemoveHiddenText() Dim nResult As Integer Dim nDeletes As Integer Dim nRemaining As Integer ' ' Start from the top of the document ' Selection.HomeKey Unit:=wdStory ' ' Display hidden text ' ActiveDocument.ActiveWindow.View.ShowHiddenText = True ' ' Find and display all instances of hidden text ' nDeletes = 0 nRemaining = 0 Do While True ' ' Find the next instance ' With Selection.Find .ClearFormatting .Text = "" .Replacement.Text = "" .Forward = True .Wrap = wdFindStop .Format = True .Font.Hidden = True .Execute ' ' Was it found? ' If .Found Then ' ' If so, ask the user if they want to delete it ' nResult = MsgBox("The following hidden text was found " & _ "in the document:" & vbCrLf & vbCrLf & _ Selection.Text & vbCrLf & vbCrLf & _ "Do you want to delete it?", _ vbYesNo, "Found Hidden Text") ' ' If Yes, delete it ' If nResult = vbYes Then Selection.Range.Delete nDeletes = nDeletes + 1 Else nRemaining = nRemaining + 1 End If Else ' ' If no more hidden text was found, ' we're done, so exit the loop ' Exit Do End If End With Loop MsgBox "Instances of hidden text deleted: " & nDeletes & vbCrLf & _ "Instances of hidden text remaining: " & nRemaining,,"Done!" End Sub This procedure sets the ShowHiddenText property to true to display the active document's hidden text. A Do loop then calls the Find method to look for the next instance of hidden text (where the Font.Hidden property is TRue). If an instance is found (the Find object's Found property is TRue), a message is displayed, like the example shown in Figure 14.15. Click Yes to delete the hidden text (and increment the nDeletes counter) or click No to leave it (and increment the nRemaining counter). When all the instances of hidden text have been found, the code exits the Do loop and another message box shows the number of instances of hidden text deleted and still remaining in the document. Figure 14.15. When the RemoveHiddenText macro finds an instance of hidden text in the active document, it displays a message box like the one shown here.
Removing HyperlinksHyperlinks in a document can cause privacy problems because they may point to local files, network shares, or web pages that contain sensitive data. Just in case, use the VBA procedure in Listing 14.2 to examine the hyperlinks and handle them accordingly (delete the entire hyperlink, including the display text; delete just the link; or do nothing).
Listing 14.2. A Procedure That Finds the Hyperlinks in the Active Document and Prompts to Delete the Entire Hyperlink or Just the LinkSub RemoveHyperlinks() Dim nResult As Integer Dim nHDeletes As Integer Dim nLDeletes As Integer Dim nRemaining As Integer Dim r As Range Dim hl As Hyperlink ' ' Initialize counters ' nHDeletes = 0 nLDeletes = 0 nRemaining = 0 ' ' Run through all the hyperlinks in the document ' For Each r In ActiveDocument.StoryRanges For Each hl In r.Hyperlinks nResult = MsgBox("The following hyperlink was found in " & _ "the document:" & vbCrLf & vbCrLf & _ "Text: " & hl.TextToDisplay & vbCrLf & _ "Link: " & hl.Address & vbCrLf & vbCrLf & _ "Click Yes to delete entire hyperlink" & vbCrLf & _ "Click No to delete just the link" & vbCrLf & _ "Click Cancel to leave the hyperlink", _ vbYesNoCancel, "Found Hyperlink") ' ' Handle the result ' Select Case nResult Case vbYes ' ' Delete the entire hyperlink ' hl.Range.Delete nHDeletes = nHDeletes + 1 Case vbNo ' ' Delete just the link ' hl.Delete nLDeletes = nLDeletes + 1 Case vbCancel ' ' Leave the hyperlink as is ' nRemaining = nRemaining + 1 End Select Next Next MsgBox "Hyperlinks deleted: " & nHDeletes & vbCrLf & _ "Links deleted: " & nLDeletes & vbCrLf & _ "Hyperlinks remaining: " & nRemaining, , "Done!" End Sub The RemoveHyperlinks procedure runs through all the hyperlinks in the active document. For each one, it displays a message that lists the hyperlink text and address and asks the user what to do with the hyperlink: delete it, delete just the link, or ignore it (refer to Figure 14.15). A Select Case structure handles the three possibilities and increments the corresponding counters. When all the hyperlinks have been handled, a message box displays the final counter totals, as shown in Figure 14.16. Figure 14.16. When the RemoveHyperlinks procedure finds a hyperlink, it displays a message box similar to the one shown here.
Remove Document VariablesAs you learned in Chapter 11, "Maximizing Office with VBA Macros," you can use program variables to store data for later use in a procedure. One common problem that VBA programmers face is how to store data between macro sessions. That is, if I run a macro today, how can I preserve the results for when I run the macro again tomorrow?
You can use a number of methods to overcome this programfor example, by storing the data in the Windows Registrybut one solution that Word VBA programmers often turn to is the document variable. This is a storage location similar to a program variable, except that instead of being stored in memory, the variable is stored in a Word document. The variable isn't visible to the user, but any VBA programmer can easily write a short procedure to enumerate a document's variables and their values. If you or someone else has used document variables to store private or sensitive data, you should clear the document variables before making the document available for public consumption. Listing 14.3 shows a procedure that removes the document variables from a Word document. Click Yes to delete the document variable (and increment the nDeletes counter) or No to leave it (and increment the nRemaining counter). When all the instances of document variables have been handled, the code displays another message box showing the number of variables deleted and still remaining in the document. Listing 14.3. A Procedure That Finds the Variables in a Document and Prompts to Delete ThemSub RemoveDocumentVariables() Dim nresult As Integer Dim nDeletes As Integer Dim nRemaining As Integer Dim v As Variable ' ' Find and display all instances of document variables ' nDeletes = 0 nRemaining = 0 For Each v In ActiveDocument.Variables ' ' In each case, ask the user if they want to delete it ' nresult = MsgBox("The following variable was found " & _ "in the document:" & vbCrLf & vbCrLf & _ "Name: " & v.Name & vbCrLf & _ "Value: " & v.Value & vbCrLf & vbCrLf & _ "Do you want to delete it?", _ vbYesNo, "Found Document Variable") ' ' If Yes, delete it ' If nresult = vbYes Then v.Delete nDeletes = nDeletes + 1 Else nRemaining = nRemaining + 1 End If Next 'v MsgBox "Document variables deleted: " & nDeletes & vbCrLf & _ "Document variables remaining: " & nRemaining, , "Done!" End Sub The RemoveDocumentVariables procedure runs through the collection of Variable objects in the active document. In each case, the procedure displays a message box showing the variable name and value, as shown in Figure 14.17. Figure 14.17. When the RemoveDocumentVariables procedure finds a document variable, it displays a message box similar to the one shown here.
Removing Field Codes with LinksAnother potential Word privacy breach is a field in which the code contains a link. For example, the IncludePicture field inserts a picture into a document by linking to an image file on a local hard disk, network share, or remote server. Similarly, the Link field inserts an object based on a pathname or URL. You should examine your document for linked field codes before publishing it.
If you have only a few fields, one way to prevent privacy problems is to display all the field codes (select Tools, Options, display the View tab, activate the Field Codes check box, and select Always in the list box). For each field that contains a link, click the field and then press Ctrl+Shift+F9 to unlink the field. If you have a number of fields, however, use the procedure in Listing 14.4 to run through all the fields automatically. Listing 14.4. A Procedure That Finds the Fields in a Document and Prompts to Delete ThemSub RemoveLinkedFields() Dim nresult As Integer Dim nDeletes As Integer Dim nUnlinks As Integer Dim nRemaining As Integer Dim f As Field ' ' Find and display all instances of document variables ' nDeletes = 0 nUnlinks = 0 nRemaining = 0 For Each f In ActiveDocument.Fields ' ' Check for a linked field ' If f.Type = wdFieldIncludePicture Or _ f.Type = wdFieldIncludeText Or _ f.Type = wdFieldLink Then ' ' In each case, ask the user if they want to delete it ' nresult = MsgBox("The following linked field was found " & _ "in the document:" & vbCrLf & vbCrLf & _ "Code: " & f.Code & vbCrLf & vbCrLf & _ "Click Yes to delete the field" & vbCrLf & _ "Click No to unlink the field" & vbCrLf & _ "Click Cancel to leave the field", _ vbYesNoCancel, "Found Linked Field") ' ' Handle the result ' Select Case nresult Case vbYes ' ' Delete the field ' f.Delete nDeletes = nDeletes + 1 Case vbNo ' ' Unlink the field ' f.Unlink nUnlinks = nUnlinks + 1 Case vbCancel ' ' Leave the field as is ' nRemaining = nRemaining + 1 End Select End If Next 'f MsgBox "Fields deleted: " & nDeletes & vbCrLf & _ "Fields unlinked: " & nUnlinks & vbCrLf & _ "Fields remaining: " & nRemaining, , "Done!" End Sub The RemoveLinkedFields procedure runs through all the fields in the active document. For each one, it tests for a linked field type; if it finds one, it displays a message that lists the field code and asks the user what to do with the field: delete it, unlink it, or ignore it (see Figure 14.18). A Select Case structure handles the three possibilities and increments the corresponding counters. When all the fields have been handled, a message box displays the final counter totals. Figure 14.18. When the RemoveLinkedFields procedure finds a field, it displays a message box similar to the one shown here.
|