2 Ways to Protect Your Privacy by Auto Deleting Personal Information from Word Document via VBA

In today’s post, we will give you 2 ways to protect your privacy by auto deleting personal information from Word document via VBA.Protect Your Privacy by Auto Deleting Personal Information from Word Document

More or less, the document we are working consists of some personal information which might expose your privacy, such as follows:Personal Information

Therefore, you need to take actions against such privacy leak, such as deleting document properties as to remove sensitive data.

In one of our previous articles, we’ve shown you the steps to manually remove personal information from document. And this time, we offer you 2 macro methods to achieve the same task in a quick and dirty manner.

Method 1: Auto Delete Personal Information while Closing a Document

  1. Firstly, press “Alt+ F11” in Word to invoke VBA editor.
  2. Next, create a new module by clicking “Normal”.
  3. Then click “Insert” and select “Module” on the drop-down menu.Click "Normal"->Click "Insert"->Click "Module"
  4. Now double click to open the module.
  5. Paste the following codes:
Sub AutoClose()
  Dim strButtonValue As String
  Dim strFile As String
  Dim objDoc As Document
 
  Set objDoc = ActiveDocument
 
  If objDoc.Path <> "" Then
    strButtonValue = MsgBox("Do you want to remove the document properties of this document?", vbYesNo)
    If strButtonValue = vbYes Then
      objDoc.RemoveDocumentInformation (wdRDIDocumentProperties)
    Else
      Exit Sub
    End If
    objDoc.Save
  End If
End Sub
  1. Next, click “Save”.Paste Codes>Click "Save"
  2. Once you close a document, you will trigger a box, asking if you want to remove the document properties of this document. Click “Yes” or “No” accordingly.Click "Yes" or "No"
  3. If you click “Yes”, the macro will automatically remove all document properties and save the document and then close it. If you choose “No”, the document will be closed immediately.

Method 2: Auto Delete Personal Information from Multiple Documents

  1. To begin with, arrange all target documents under one directory.
  2. Next open Word and follow above steps to install macro.
  3. Then paste these codes:
Sub RemoveDocPropertiesOfMultiDoc()
  Dim strButtonValue As String
  Dim strFile As String
  Dim objDoc As Document
  Dim StrFolder As String
  Dim dlgFile As FileDialog
 
  Set dlgFile = Application.FileDialog(msoFileDialogFolderPicker)
 
  With dlgFile
    If .Show = -1 Then
      StrFolder = .SelectedItems(1) & "\"
    Else
      MsgBox "No folder is selected! Please select the target folder."
      Exit Sub
    End If
  End With
 
  strFile = Dir(StrFolder & "*.docx", vbNormal)
 
  While strFile <> ""
    Set objDoc = Documents.Open(FileName:=StrFolder & strFile)
    objDoc.RemoveDocumentInformation (wdRDIDocumentProperties)
    objDoc.Save
    objDoc.Close
    strFile = Dir()
  Wend
End Sub
  1. Click “Run” or press “F5” to get codes executed.Paste Codes->Click "Run"
  2. Now in the “Browse” window open, select the folder where you keep documents.
  3. Lastly, click “OK” and let Word do its job.Select a Folder->Click "OK"

Cope with Word Errors

A simple user error can bring down Word, and leave documents damaged. If don’t act effectively, there is a high chance to lose all data. So, it’s advised to obtain a preeminent tool to repair doc as soon as possible.

Author Introduction:

Vera Chen is a data recovery expert in DataNumen, Inc., which is the world leader in data recovery technologies, including corrupt Excel and pdf repair software products. For more information visit www.datanumen.com

Comments are closed.