|
|
Title | Remove personal information from a Word file |
Description | This example shows how to remove personal information from a Word file in Visual Basic 6. |
Keywords | Word, Microsoft Word, Office, Microsoft Office, personal information |
Categories | Office, Miscellany |
|
|
This program requires a reference to the Word object model. Select Project/Add Reference. Click the COM tab and select "Microsoft Word 11.0 Object Library" (or whatever version you have on your system).
When you click the Open button, the program creates a Word server and opens the document. It sets the document's RemovePersonalInformation property to True and saves the file. This removes the personal information from the file and makes the file not save that information in the future.
|
|
Private Sub cmdOpen_Click()
Dim word_app As Word.Application
Dim word_doc As Word.Document
' Make a Word server object.
Set word_app = New Word.Application
word_app.Visible = False
' Open the Document.
On Error GoTo OpenError
Set word_doc = word_app.Documents.Open(txtFile.Text)
On Error GoTo 0
' Remove personal information.
word_doc.RemovePersonalInformation = True
' Save and close the document.
word_doc.Close True
Set word_doc = Nothing
' Clean up.
word_app.Quit
Set word_app = Nothing
MsgBox "Ok"
Exit Sub
OpenError:
MsgBox "Error opening file." & vbCrLf & Err.Description
word_app.Quit
Set word_app = Nothing
Exit Sub
End Sub
|
|
Note that the RemovePersonalInformation property is relatively new so this will not work on older versions of Word. It works with the Word 10.0 object library but not with the 9.0 library.
For more information on programming Word and other Microsoft Office applications with VBA, see my book Microsoft Office Programming: A Guide for Experienced Developers.
|
|
|
|
|
|