Run the Doc Inspector and Delete All Info

Microsoft Office 2007 small business wit...
August 1, 2010 at 16:25:36
Specs: Windows XP
Hello,

Would you be able to help out with this?

We need to run a macro that would allow us to delete all info a Word 2007 doc, i.e
1) Comments, Revisions, Versions, and Annotations
2) Custom XML Data
3) Document Properties and Personal Information
4) Headers and Footers
5) Hidden Text

When I record a macro, it seems to pick only item 1) and 3) as shown below

ActiveDocument.RemoveDocumentInformation (wdRDIComments)
ActiveDocument.RemoveDocumentInformation (wdRDIDocumentProperties)
ActiveDocument.RemoveDocumentInformation (wdRDIRemovePersonalInformation)

2), 4) and 5) do not even show in the macro.

Is there a way to do a total clean up (all 5 categories) in one go?

Thank you very much


See More: Run the Doc Inspector and Delete All Info

Report •


#1
August 3, 2010 at 09:12:16
Hi,

Have you tried using Word 2007's built-in remover.

From Word's Office button, select 'Prepare'
Then select 'Inspect Document'
Save the document if not already saved - follow the prompts
Then accept all the checked options:
Comments, properties, personal info. etc.

Click 'Inspect'
Click each 'Remove all' button
then 'Close'

Saving as Read-only should stop new personal information being reintroduced into the file before it is despatched -
Select 'Prepare' again, and 'Mark as final'

This saves it as Read only, although it's status can be changed when it is reopened or opened by a recipient. However if you have Word 2003 as well as Word 2007, this protection apparently is not available (see the Help file - enter: "prevent changes to a final version"). In any case it's just a warning to not change and save the document again, and thus add new personal info.

Regards


Report •

#2
August 3, 2010 at 13:37:27
Hi Humar,

Thank you for your reply.
Yes, indeed, I have been using the Word 2007 built-in remover.
Manually, it does the job, but I need to apply the procedure to several hundred of files and I was wondering if there is way to create macro (that actually removes all 5 items in Word Inspect). If this was possible, I could easily automate the process (open/run macro/close).
Regards,


Report •

#3
August 3, 2010 at 14:33:12
Hi,

The macro may have only shown a limited number of options as the document you ran it on did not have the other information in it.

This page has a list of all the Remove types, including one to remove all hidden/personal information.

I haven't tested it, but it looks promising.
ActiveDocument.RemoveDocumentInformation (wdRDIAll)

Regards


Report •

Related Solutions

#4
August 3, 2010 at 17:17:38
Hello Humar,

I always use the "BatchChange" macro below to run any embedded macro and it has never failed but his time it halts on ActiveDocument.RemoveDocumentInformation (wdRDIAll). I cannot pintpoint the problem
Regards,

Sub BatchChange()
'
' BatchChange Macro
' Macro recorded on 06/03/2008
'
Dim strDocPath As String
Dim strCurDoc As String
Dim docCurDoc As Document

strDocPath = "C:\Path\SourceTargetFolder"
strCurDoc = Dir(strDocPath & "*.doc")
Do While strCurDoc <> ""
Application.Run MacroName:="DeletePropertiesWord2007"
docCurDoc.Close wdSaveChanges
strCurDoc = Dir
Loop
MsgBox "Completed"
End Sub

Sub DeletePropertiesWord2007()
'
' DeletePropertiesWord2007 Macro
'
'
ActiveDocument.RemoveDocumentInformation (wdRDIAll)

End Sub


Report •

#5
August 4, 2010 at 04:08:56
Hi,

The problem may relate to ActiveDocument.

Your main macro is referencing docCurDoc but is not selecting it.

You might try passing docCurDoc to the sub:
Application.Run MacroName:="DeletePropertiesWord2007", Varg1:=docCurDoc

Sub DeletePropertiesWord2007(wd as Document)
' DeletePropertiesWord2007 Macro
wd.RemoveDocumentInformation (wdRDIAll)
End Sub

Regards


Report •

#6
August 4, 2010 at 13:43:11
Hello,

Thank you again.
I am not a 100% sure I understood. Actually, I just made the change you recommended and it now reads as follows. It still stops on the same "line" (Application.Run MacroName:="DeletePropertiesWord2007", Varg1:=docCurDoc) but, again, I might have misunderstood your explanation.

Regards,

Sub BatchChange()
'
' BatchChange Macro
' Macro recorded on 06/03/2008
'
Dim strDocPath As String
Dim strCurDoc As String
Dim docCurDoc As Document

strDocPath = "C:\Path\SourceTargetFolder"
strCurDoc = Dir(strDocPath & "*.doc")
Do While strCurDoc <> ""
Application.Run MacroName:="DeletePropertiesWord2007", Varg1:=docCurDoc
docCurDoc.Close wdSaveChanges
strCurDoc = Dir
Loop
MsgBox "Completed"
End Sub


Sub DeletePropertiesWord2007(wd as Document)
' DeletePropertiesWord2007 Macro
wd.RemoveDocumentInformation (wdRDIAll)
End Sub


Report •

#7
August 4, 2010 at 15:26:05
Hi,

Ahh... strCurDoc is the name of a document, not the document itself.

So you will need to open the document then change, save and close it.

Try this:

Do While strCurDoc <> ""
   Application.Documents.Open FileName:=strCurDoc
   Set wd = Documents(strCurDoc)
   Application.Run MacroName:="DeletePropertiesWord2007",  Varg1:=wd
   wd.Close wdSaveChanges
   strCurDoc = Dir
Loop
...

Regards



Report •

#8
August 4, 2010 at 16:14:11
Hello,
I did make the changes and the behavior is different.
The macro does open the first file in the folder which displays on screen, but it then halts on the same line.
It returns
Run-time Error 450
Wrong arguments or Invalid property.
Humar, I know you have spent some time on this very kindly so I 'll understand quite well if you close this thread.
Regards,

Report •

#9
August 4, 2010 at 19:26:51
Hello Humar,

I think I should stop thinking about this process. You know why. I just tried again the simple command "ActiveDocument.RemoveDocumentInformation (wdRDIAll)" on a single document which contained all the properties (but hidden text) and it does not do what it is supposed to do ; i.e it does not pick "headers and footers" and it does not pick "XML" either. So I think we might waste our time trying to embed this macro into a batch-sequence macro.
Thank you again for you help.


Report •

#10
August 5, 2010 at 04:58:40
Hi,

Edit:
Posted this before I saw your response. Thanks for letting me know, I will leave it now.
....

I wrote the following as a single stand-alone macro.

It offers an Open file dialog box, where documents can be selected. Once selected and Open is clicked, each selected document is opened, cleaned, and saved/closed.

The Open dialog box is pre-filtered for document types
Changes this line as required:

Application.FileDialog(msoFileDialogOpen).Filters.Add _
        Description:="Word documents (*.doc; *.docx)", _
        Extensions:="*.doc;*.docx"

The following line sets the initial directory (remove it completely to start at 'My Computer') or edit as appropriate:
.InitialFileName = "C:\temp\"

I wasn't able to test this fully as the remove document information function is only available in Word 2007 or later and I only have 2003 on this PC.
Anyway here is the code:
Option Explicit

Sub ClearDocs()
Dim wdd As Document
Dim intRetVal As Integer
Dim n As Integer

On Error GoTo ErrHnd

'turn off screen updating so we don't see
'all the documents opened and closed again
Application.ScreenUpdating = False

'set the file open dialog filters
Application.FileDialog(msoFileDialogOpen).Filters.Clear
Application.FileDialog(msoFileDialogOpen).Filters.Add _
        Description:="Word documents (*.doc; *.docx)", _
        Extensions:="*.doc;*.docx"

'setup and show the Open dialog box
With Application.FileDialog(msoFileDialogOpen)
    .Title = "Select Documents to Clean"
    'set start folder
    .InitialFileName = "C:\temp\"
    .AllowMultiSelect = True
    'show the dialog box and get the button that was clicked
    intRetVal = .Show
    'check that user selected Open (-1) rather than Cancel (0)
    If intRetVal = -1 Then
        'iterate through the selected documents
        For n = 1 To .SelectedItems.Count
            'open document
            Set wdd = Documents.Open(.SelectedItems(n))
            'clear personal data from document
            wdd.RemoveDocumentInformation (wdRDIAll)
            'save and close document
            wdd.Close SaveChanges:=True
        Next n
    End If
End With
'turn on screen updating
Application.ScreenUpdating = True
Exit Sub

'error handler
ErrHnd:
Err.Clear
'turn on screen updating
Application.ScreenUpdating = True
End Sub

Regards


Report •

#11
August 5, 2010 at 17:45:57
Hi Humar,

Your macro works perfectly. The problem definitely lies with the action of wdRDIAll which only deletes personal info but not the rest of the properties.
Thank you again for you kind help and patience.

Regards,


Report •


Ask Question