Discussion:
Delete or reset values for all custom document properties
(too old to reply)
Eric F.
2007-11-26 23:21:19 UTC
Permalink
As part of an automated document cleanup process, I created a VBA userform
that lets the user select up to 14 kinds of things to be removed from a Word
document (tracked changes, comments, hidden text, etc.) This is kind of an
ersatz Remove Hidden Data tool.

I would like to be able to include in this form the option to remove any
custom document properties that have been set in a Word document before we
send the document outside the office. We sometimes send many dozens of files
at once and each may have many custom document properties set for it. We have
received files from outside the office that contained custom document
properties that I know the sender would not have wanted us to see and I want
to make sure we avoid that same problem.

The problem is I can't find a way to automatically remove all custom
properties. These can be of two kinds: the custom document properties that
are already in the document (from the template - I can manually delete the
value but the name remains) and those created by document users (I can
manually delete both the property name and the value for these). While it is
quite easy to add new custom document properties and property values with
VBA, I cannot find a way to automatically delete all custom document
properties or their values. I can automatically remove the values for those
custom document properties that are in the template (since I know each
property's name) but I cannot find a way to delete or at least remove the
value for a custom property created by a user. It would be sufficient for me
to reset the value of a user-created custom document property to no data or a
space or some other text, but I have been unable to get anything to work.
Although just removing the value might leave the user-created custom property
name visible in the document properties, at least the value would be gone. At
this point, I don't need to choose to keep any custom document properties. It
appears that it will be sufficient to just remove all and I don't need the
option to preserve some of the custom properties for the files we send out. I
have searched several groups and through the VBA help but can't find a
solution. I would appreciate help with some VBA code that would handle all
the custom document properties. Thanks.
Greg Maxey
2007-11-27 00:01:50 UTC
Permalink
Sub ScratchMacro1()
'This will delete user added Custom Properties and set the value of built-in
'Custom Properties to nothing
Dim oProp As DocumentProperty
For Each oProp In ActiveDocument.CustomDocumentProperties
MsgBox oProp.Name
MsgBox oProp.Value
oProp.Delete
Next
End Sub


I wouldn't mind seeing that UserForm.
--
Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.
Post by Eric F.
As part of an automated document cleanup process, I created a VBA
userform that lets the user select up to 14 kinds of things to be
removed from a Word document (tracked changes, comments, hidden text,
etc.) This is kind of an ersatz Remove Hidden Data tool.
I would like to be able to include in this form the option to remove
any custom document properties that have been set in a Word document
before we send the document outside the office. We sometimes send
many dozens of files at once and each may have many custom document
properties set for it. We have received files from outside the office
that contained custom document properties that I know the sender
would not have wanted us to see and I want to make sure we avoid that
same problem.
The problem is I can't find a way to automatically remove all custom
properties. These can be of two kinds: the custom document properties
that are already in the document (from the template - I can manually
delete the value but the name remains) and those created by document
users (I can manually delete both the property name and the value for
these). While it is quite easy to add new custom document properties
and property values with VBA, I cannot find a way to automatically
delete all custom document properties or their values. I can
automatically remove the values for those custom document properties
that are in the template (since I know each property's name) but I
cannot find a way to delete or at least remove the value for a custom
property created by a user. It would be sufficient for me to reset
the value of a user-created custom document property to no data or a
space or some other text, but I have been unable to get anything to
work. Although just removing the value might leave the user-created
custom property name visible in the document properties, at least the
value would be gone. At this point, I don't need to choose to keep
any custom document properties. It appears that it will be sufficient
to just remove all and I don't need the option to preserve some of
the custom properties for the files we send out. I have searched
several groups and through the VBA help but can't find a solution. I
would appreciate help with some VBA code that would handle all the
custom document properties. Thanks.
Eric F.
2007-11-27 20:10:03 UTC
Permalink
Thanks for the quick reply. It works well. I am teaching myself VBA and have
quite a ways to go.

I can send you the UserForm. It is pretty basic and I am sure the underlying
code could be much more efficient. The UserForm currently has 14 check boxes
with most pre-checked. I have buttons to select all, select none, or reset to
the default selections as well as "OK" and "Cancel." The OK button executes
separate macros based on which checkboxes are selected. I wrote some of the
macros but most of the macros are ones I have found on this site, the Word
MVP site, Microsoft's knowledgebase, and other forums/groups. I believe
several of the macros have code that originally came from you. I have tweaked
some of the macros I have found to get functionality I thought I wanted. Many
of the items are ones identified by Microsoft in the "How to minimize
metadata in Word 2003" knowledgebase article
<http://support.microsoft.com/kb/825576/en-us>. Other items just came from
observing how people edit documents (like using highlighting and different
font colors to "comment" on something).

The current options are: clear Routing Slip info, turn Track Changes off,
delete any Versions, turn off FastSave, unlink field links, reset the
template to normal.dot, accept tracked changes and delete comments and ink
annotations, delete hidden text, clear any search entries, Microsoft's Remove
Personal information, remove hyperlinks, delete document variables, clear
highlighting, and set font color to black. I may add a couple more items and
may add in things like asking the user if they want to start out with a "save
as" and if the want to make the document read-only and password protected. I
would certainly be open to any suggestions that anyone might have.

Again, thanks Greg.

Eric F.
Post by Greg Maxey
Sub ScratchMacro1()
'This will delete user added Custom Properties and set the value of built-in
'Custom Properties to nothing
Dim oProp As DocumentProperty
For Each oProp In ActiveDocument.CustomDocumentProperties
MsgBox oProp.Name
MsgBox oProp.Value
oProp.Delete
Next
End Sub
I wouldn't mind seeing that UserForm.
--
Greg Maxey/Word MVP
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.
Post by Eric F.
As part of an automated document cleanup process, I created a VBA
userform that lets the user select up to 14 kinds of things to be
removed from a Word document (tracked changes, comments, hidden text,
etc.) This is kind of an ersatz Remove Hidden Data tool.
I would like to be able to include in this form the option to remove
any custom document properties that have been set in a Word document
before we send the document outside the office. We sometimes send
many dozens of files at once and each may have many custom document
properties set for it. We have received files from outside the office
that contained custom document properties that I know the sender
would not have wanted us to see and I want to make sure we avoid that
same problem.
The problem is I can't find a way to automatically remove all custom
properties. These can be of two kinds: the custom document properties
that are already in the document (from the template - I can manually
delete the value but the name remains) and those created by document
users (I can manually delete both the property name and the value for
these). While it is quite easy to add new custom document properties
and property values with VBA, I cannot find a way to automatically
delete all custom document properties or their values. I can
automatically remove the values for those custom document properties
that are in the template (since I know each property's name) but I
cannot find a way to delete or at least remove the value for a custom
property created by a user. It would be sufficient for me to reset
the value of a user-created custom document property to no data or a
space or some other text, but I have been unable to get anything to
work. Although just removing the value might leave the user-created
custom property name visible in the document properties, at least the
value would be gone. At this point, I don't need to choose to keep
any custom document properties. It appears that it will be sufficient
to just remove all and I don't need the option to preserve some of
the custom properties for the files we send out. I have searched
several groups and through the VBA help but can't find a solution. I
would appreciate help with some VBA code that would handle all the
custom document properties. Thanks.
Greg Maxey
2007-11-28 00:33:32 UTC
Permalink
Yes, I would like to see what you have done.
--
Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.
Post by Eric F.
Thanks for the quick reply. It works well. I am teaching myself VBA
and have quite a ways to go.
I can send you the UserForm. It is pretty basic and I am sure the
underlying code could be much more efficient. The UserForm currently
has 14 check boxes with most pre-checked. I have buttons to select
all, select none, or reset to the default selections as well as "OK"
and "Cancel." The OK button executes separate macros based on which
checkboxes are selected. I wrote some of the macros but most of the
macros are ones I have found on this site, the Word MVP site,
Microsoft's knowledgebase, and other forums/groups. I believe several
of the macros have code that originally came from you. I have tweaked
some of the macros I have found to get functionality I thought I
wanted. Many of the items are ones identified by Microsoft in the
"How to minimize metadata in Word 2003" knowledgebase article
<http://support.microsoft.com/kb/825576/en-us>. Other items just came
from observing how people edit documents (like using highlighting and
different font colors to "comment" on something).
The current options are: clear Routing Slip info, turn Track Changes
off, delete any Versions, turn off FastSave, unlink field links,
reset the template to normal.dot, accept tracked changes and delete
comments and ink annotations, delete hidden text, clear any search
entries, Microsoft's Remove Personal information, remove hyperlinks,
delete document variables, clear highlighting, and set font color to
black. I may add a couple more items and may add in things like
asking the user if they want to start out with a "save as" and if the
want to make the document read-only and password protected. I would
certainly be open to any suggestions that anyone might have.
Again, thanks Greg.
Eric F.
Post by Greg Maxey
Sub ScratchMacro1()
'This will delete user added Custom Properties and set the value of
built-in 'Custom Properties to nothing
Dim oProp As DocumentProperty
For Each oProp In ActiveDocument.CustomDocumentProperties
MsgBox oProp.Name
MsgBox oProp.Value
oProp.Delete
Next
End Sub
I wouldn't mind seeing that UserForm.
--
Greg Maxey/Word MVP
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.
Post by Eric F.
As part of an automated document cleanup process, I created a VBA
userform that lets the user select up to 14 kinds of things to be
removed from a Word document (tracked changes, comments, hidden
text, etc.) This is kind of an ersatz Remove Hidden Data tool.
I would like to be able to include in this form the option to remove
any custom document properties that have been set in a Word document
before we send the document outside the office. We sometimes send
many dozens of files at once and each may have many custom document
properties set for it. We have received files from outside the
office that contained custom document properties that I know the
sender would not have wanted us to see and I want to make sure we
avoid that same problem.
The problem is I can't find a way to automatically remove all custom
properties. These can be of two kinds: the custom document
properties that are already in the document (from the template - I
can manually delete the value but the name remains) and those
created by document users (I can manually delete both the property
name and the value for these). While it is quite easy to add new
custom document properties and property values with VBA, I cannot
find a way to automatically delete all custom document properties
or their values. I can automatically remove the values for those
custom document properties that are in the template (since I know
each property's name) but I cannot find a way to delete or at least
remove the value for a custom property created by a user. It would
be sufficient for me to reset the value of a user-created custom
document property to no data or a space or some other text, but I
have been unable to get anything to work. Although just removing
the value might leave the user-created custom property name visible
in the document properties, at least the value would be gone. At
this point, I don't need to choose to keep any custom document
properties. It appears that it will be sufficient to just remove
all and I don't need the option to preserve some of the custom
properties for the files we send out. I have searched several
groups and through the VBA help but can't find a solution. I would
appreciate help with some VBA code that would handle all the custom
document properties. Thanks.
Loading...