Reputation: 300
I can't read the value here when opening excel
DocumentProperties properties;
var wb = Globals.ThisAddIn.Application.ActiveWorkbook;
or
var wb = Globals.ThisAddIn.Application.ThisWorkbook;
if (wb is null)
{
return "";
}
properties = ( DocumentProperties)wb.CustomDocumentProperties;
foreach (DocumentProperty prop in properties)
{
if (prop.Name == propertyName)
{
return prop.Value.ToString();
}
}
ActiveWorkbook and ThisWorkbook are both null when opening excel.
What I want to do is read the public value of the customdocumentproperties and make it selected in the ribbon.
Upvotes: 0
Views: 75
Reputation: 49395
It is not clear whether such values are known and predefined or not. Let's consider both cases then...
If values are predefined you can design your custom UI based on the list of predefined controls. By using the getEnabled
callback you could manage of the buttons state. For example, by default, controls are disabled and greyed out. As soon as users open a document with custom document properties you can read values and force your custom ribbon UI to refresh. The Invalidate or InvalidateControl methods of the IRibbonUI
interface which allows invalidating the cached values for all of the controls (or particular one) of the Ribbon user interface.
In the case of unknown values you can use controls that can be populated at runtime. So, when a document is opened and custom document properties are read you could populate controls at runtime by using the getContent
callback from the dynamicMenu
control. The callback's signature is shown below:
C#: string GetContent(IRibbonControl control)
VBA: Sub GetContent(control As IRibbonControl, ByRef content)
C++: HRESULT GetContent([in] IRibbonControl *pControl, [out, retval] BSTR *pbstrContent)
Visual Basic: Function GetContent(control As IRibbonControl) As String
Read more about the Fluent UI (aka Ribbon UI) in the following series of articles:
Upvotes: 1