Mehmet Ceylan
Mehmet Ceylan

Reputation: 300

Reading the public value of customdocumentproperties and making it selected in the ribbon

enter image description here 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.

enter image description here

Upvotes: 0

Views: 75

Answers (1)

Eugene Astafiev
Eugene Astafiev

Reputation: 49395

It is not clear whether such values are known and predefined or not. Let's consider both cases then...

  1. 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.

  2. 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

Related Questions