Custom Document Properties

J

JAC

Does anyone know how to remove a specified Custom Document Property
from an Excel workbook using VBA?
Adding is easy. There is a method to Add.

I tried to use the Macro Recorder while trying to delete a property
manually, but it did not record anything useful.
Thank you in anticipation.
 
C

Carlos

Hi JAC,

Suppose I already have a custom property named "CustomNumber" in the
workbook object wbk. To erase it just write:

Call wbk.CustomDocumentProperties("CustomNumber").Delete

Custom Properties work like any other collection. You should take a look to
the help file of the collection object.
 
C

Chip Pearson

There is also a Delete method. Try something like the following:

Dim DocProps As Office.DocumentProperties
Dim DocProp As Office.DocumentProperty
Set DocProps = ThisWorkbook.CustomDocumentProperties
Set DocProp = DocProps("MyProp") ' Here it is.
Debug.Print DocProp.Value
DocProps.Item("MyProp").Delete ' Now it's gone

Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)
 
J

JAC

Hi JAC,

Suppose I already have a custom property named "CustomNumber" in the
workbook object wbk. To erase it just write:

Call wbk.CustomDocumentProperties("CustomNumber").Delete

Custom Properties work like any other collection. You should take a look to
the help file of the collection object.

Thanks guys.

I don't know why I didn't think of that. It's so blindingly obvious
when you think about it.

I hope that others find it useful that the problem has been aired.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top