ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Storing add-in properties with workbook - how to? (VSTO 2007) (https://www.excelbanter.com/excel-programming/433975-storing-add-properties-workbook-how-vsto-2007-a.html)

Thomas[_24_]

Storing add-in properties with workbook - how to? (VSTO 2007)
 
Hello Developers,

Where/how do I store Excel VSTO add-in properties with workbook? Is it
possible?

I would rather store some of my add-in properties somewhere within the
workbook, rather than in registry or in a separate file since those
properties are workbook specific.

Thanks for any pointers.

Thomas


Jim Thomlinson

Storing add-in properties with workbook - how to? (VSTO 2007)
 
One place to keep properties is in named ranges. Global properties can go in
global range names while sheet specific properties can be store in local
named ranges. They are easy to read from and write to. I know of at least one
commercial application that uses this technique quite successfully.
--
HTH...

Jim Thomlinson


"Thomas" wrote:

Hello Developers,

Where/how do I store Excel VSTO add-in properties with workbook? Is it
possible?

I would rather store some of my add-in properties somewhere within the
workbook, rather than in registry or in a separate file since those
properties are workbook specific.

Thanks for any pointers.

Thomas



Colbert Zhou [MSFT]

Storing add-in properties with workbook - how to? (VSTO 2007)
 
Hello Thomas,

We can store the add-in properties in Workbook.CustomDocumentProperties.

Microsoft Office Excel 2003 and Microsoft Office Word 2003 provide built-in
properties that are stored with workbooks and documents. In addition, you
can create and modify custom document properties if there is additional
information you want to store with the document.

Use the CustomDocumentProperties property to work with custom properties.
This property returns 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 Excel
and assign it a value.
-----------------VB.NET-----------------------
Visual Basic Copy Code
Sub TestProperties()
Dim properties As Microsoft.Office.Core.DocumentProperties
properties = CType(Me.CustomDocumentProperties,
Office.DocumentProperties)

If ReadDocumentProperty("Project Name") < Nothing Then
properties("Project Name").Delete()
End If

properties.Add("Project Name", False, _
Microsoft.Office.Core.MsoDocProperties.msoProperty TypeString, _
"White Papers")
End Sub

Private Function ReadDocumentProperty(ByVal propertyName As String) As
String
Dim properties As Office.DocumentProperties
properties = CType(Me.CustomDocumentProperties,
Office.DocumentProperties)

Dim prop As Office.DocumentProperty

For Each prop In properties
If prop.Name = propertyName Then
Return prop.Value.ToString()
End If
Next

Return Nothing
End Function

-----------------------C#-------------------------------------------
C# Copy Code
void TestProperties()
{
Microsoft.Office.Core.DocumentProperties properties;
properties = (Office.DocumentProperties)this.CustomDocumentProp erties;

if (ReadDocumentProperty("Project Name") != null)
{
properties["Project Name"].Delete();
}

properties.Add("Project Name", false,
Microsoft.Office.Core.MsoDocProperties.msoProperty TypeString,
"White Papers", missing);
}

private string ReadDocumentProperty(string propertyName)
{
Office.DocumentProperties properties;
properties = (Office.DocumentProperties)this.CustomDocumentProp erties;

foreach (Office.DocumentProperty prop in properties)
{
if (prop.Name == propertyName)
{
return prop.Value.ToString();
}
}
return null;
}

You can get more information from the MSDN online documentations,
http://msdn.microsoft.com/en-us/libr...75(VS.80).aspx

Have a nice day!

Best regards,
Ji Zhou
Microsoft Managed Newsgroup Support Team



All times are GMT +1. The time now is 06:54 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com