Events
May 19, 6 PM - May 23, 12 AM
Calling all developers, creators, and AI innovators to join us in Seattle @Microsoft Build May 19-22.
Register todayThis browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
The Microsoft Office applications listed above provide built-in properties that are stored with documents. In addition, you can create and modify custom document properties if there is additional information you want to store with the document.
Applies to: The information in this topic applies to document-level projects and VSTO Add-in projects for the following applications: Excel; PowerPoint; Project; Word. For more information, see Features available by Office application and project type.
Use the CustomDocumentProperties property of a document to work with custom properties. For example, in a document-level project for Microsoft Office Excel, use the CustomDocumentProperties property of the ThisWorkbook
class. In a VSTO Add-in project for Excel, use the CustomDocumentProperties property of a Workbook object. These properties return a DocumentProperties object, which is a collection of DocumentProperty objects. You can use the Item
property of the collection to retrieve a particular property, either by name or by index within the collection.
The following example demonstrates how to add a custom property in a document-level customization for Excel and assign it a value.
void TestProperties()
{
Microsoft.Office.Core.DocumentProperties properties;
properties = (Office.DocumentProperties)this.CustomDocumentProperties;
if (ReadDocumentProperty("Project Name") != null)
{
properties["Project Name"].Delete();
}
properties.Add("Project Name", false,
Microsoft.Office.Core.MsoDocProperties.msoPropertyTypeString,
"White Papers");
}
private string ReadDocumentProperty(string propertyName)
{
Office.DocumentProperties properties;
properties = (Office.DocumentProperties)this.CustomDocumentProperties;
foreach (Office.DocumentProperty prop in properties)
{
if (prop.Name == propertyName)
{
return prop.Value.ToString();
}
}
return null;
}
Attempting to access the Value
property for undefined properties raises an exception.
Events
May 19, 6 PM - May 23, 12 AM
Calling all developers, creators, and AI innovators to join us in Seattle @Microsoft Build May 19-22.
Register today