How to update Ribbon tag text in AutoOpen() function

811 views
Skip to first unread message

Sandeep Chopra

unread,
Mar 15, 2012, 2:50:58 PM3/15/12
to Excel-DNA
Hi,

I want to append some text like "IsOutOfDate" to my custom excel dna
add-in ribbon tag text if the client version is out dated. I want to
place the version check code in AutoOpen and if the version doesn't
match then change the tag text so that the excel clients come to know
of it and then download the add-in updates using a separate add-in
installer programmer which i have written.

The excel add-in program is in C# and I have the ribbon xml in the dna
file under CustomUI tag.

I am not sure how I can access the Ribbon controls in the AutoOpen()
method of IExcelAddIn interface. Any help/advise on this would really
help.


Regards,
Sandeep

Govert van Drimmelen

unread,
Mar 15, 2012, 4:34:14 PM3/15/12
to Excel-DNA
Hi Sandeep,

There are different approaches.

One way is to override the xml returned to Excel, making some changes
before you return the string. You'd do this by overridding the
ExcelRibbon-derived class's GetCustomUI(...) method. When doing this,
you can return the customUI xml string from a resource, or you can
call base.GetCustomUI(...) to retrieve the string as Excel-DNA would
normally (maybe from your .dna file) and then make some modifications
to the string before returning it to Excel.

If you want a more dynamic ribbon, you can have a look at the
excellent articles here (this is part 3 of 3):
http://msdn.microsoft.com/en-us/library/aa722523(v=office.12).aspx.
You'll notice that many of the ribbon 'properties' come in two
flavours - a fixed value returned as part of the ribbon xml and a
dynamic flavour, which invokes a callback to get the value.
For example, for most controls you can either set the 'label'
attribute in the xml, or you can set a 'getLabel' property pointing to
an appropriate callback on your ExcelRibbon-derived class. The
signatures (in C# and VB.NET) that make a callback match are listed in
the article I point to above.

Particularly interesting for your case might be the 'getEnabled' or
'getVisible' callbacks, so that you only show or enable some button or
part of the ribbon if an update is currently available.

If you have any problems getting these ribbon customisations to work
with your Excel-DNA add-in, please write again.

Regards,
Govert

Sandeep Chopra

unread,
Mar 16, 2012, 1:59:06 PM3/16/12
to Excel-DNA
Hi Govert,

Thanks for the suggestions, i tried option 1 however it didn't work
for me. When i keep the ribbon xml in dna file it works properly but
when i try to return the same through overriden GetCustomUI() method
it doesn't work. Below is the dna file & the overriden GetCustomUI
function definition. The ribbon class resides in
Nomura.Fir.Excel.Addin.dll and is declared as ComVisible="true". So
please advise what might be going wrong here.


<DnaLibrary Name="FIR Excel Add-In" RuntimeVersion="v4.0">
<ExternalLibrary Path="Nomura.Fir.Excel.Addin.dll"
LoadFromBytes="true"/>
<Reference AssemblyPath="Nomura.Fir.ServiceModel.dll"
LoadFromBytes="true"/>
<Reference AssemblyPath="Nomura.Fir.Configuration.dll"
LoadFromBytes="true"/>

<Image Name="config" Path="configuration.png"/>
<Image Name="excelTools" Path="excel_tools.png"/>
<Image Name="email" Path="mail.png"/>
<Image Name="view" Path="view.png"/>
<Image Name="help" Path="help.png"/>

<CustomUI>
<customUI xmlns="http://schemas.microsoft.com/office/2006/01/
customui" loadImage='LoadImage'>
<ribbon>
<tabs>
<tab id="FirExcelDNAAddIn" label="FIR Add-In">
<group id="FirExcelAddinGroup" label="FIR Add-In">
<button id="ConfigManager" onAction="OnConfigManagerClicked"
label="Manage Configuration"
size="large" image="config"/>
<button id="ExcelToolsExplorer"
onAction="OnExcelToolsExplorerClicked"
label="Excel Tools"
supertip="Download FIR Excel Tools"
size="large" image="excelTools"/>
<button id="EmailLog" onAction="OnEmailLogClicked"
label="E-mail Log"
size="large" image="email"/>
<button id="ViewLog" onAction="OnViewLogClicked"
label="View Log"
size="large" image="view"/>
<button id="ViewHelp" onAction="OnViewHelpClicked"
label="Help"
enabled="true"
size="large" image="help"/>
</group>
</tab>
</tabs>
</ribbon>
</customUI>
</CustomUI>

</DnaLibrary>



public override string GetCustomUI(string uiName)
{

//return Nomura.Fir.Excel.Addin.Resources.RibbonXml;
return @"<customUI xmlns='http://schemas.microsoft.com/
office/2006/01/customui' loadImage='LoadImage'>
<ribbon>
<tabs>
<tab id='FirExcelDNAAddIn'
label='FIR Add-In 2'>
<group
id='FirExcelAddinGroup' label='FIR Add-In'>
<button
id='ConfigManager' onAction='OnConfigManagerClicked'
label='Manage
Configuration'
size='large'
image='config'/>
<button
id='ExcelToolsExplorer' onAction='OnExcelToolsExplorerClicked'
label='Excel
Tools'

supertip=Download FIR Excel Tools'
size=large
image='excelTools'/>
<button id='EmailLog'
onAction='OnEmailLogClicked'
label='E-mail
Log'
size='large'
image='email'/>
<button id='ViewLog'
onAction='OnViewLogClicked'
label='View
Log'
size='large'
image='view'/>
<button id='ViewHelp'
onAction='OnViewHelpClicked'
label='Help'
enabled='true'
size='large'
image='help'/>
</group>
</tab>
</tabs>
</ribbon>
</customUI>";
> > Sandeep- Hide quoted text -
>
> - Show quoted text -

Govert van Drimmelen

unread,
Mar 16, 2012, 3:11:36 PM3/16/12
to Excel-DNA
Hi Sandeep,

You're doing everything right.

The problem is that there are some xml syntax errors in your ribbon
string, so Excel (silently) refuses to load it.

I fixed these two:
size=large ==> size='large'
supertip=Download .... ==> supertip='Download ...

I paste the fixed version below which loaded fine for me (though
Google Groups formatting makes a mess).

Regards,
Govert

public override string GetCustomUI(string uiName)
{

//return Nomura.Fir.Excel.Addin.Resources.RibbonXml;
return @"<customUI xmlns='http://schemas.microsoft.com/
office/2006/01/customui' loadImage='LoadImage'>
<ribbon>
<tabs>
<tab id='FirExcelDNAAddIn'
label='FIR Add-In 2'>
<group
id='FirExcelAddinGroup' label='FIR Add-In'>
<button
id='ConfigManager' onAction='OnConfigManagerClicked'

label='ManageConfiguration'
</customUI>";

Sandeep Chopra

unread,
Mar 17, 2012, 12:06:44 AM3/17/12
to Excel-DNA
Many Thanks Govert, it's working for me now :)

Regards,
Sandeep Chopra
> > > > I want to append  some text like "IsOutOfDate" to my custom excel- Hide quoted text -
>
> - Show quoted text -...
>
> read more »
Reply all
Reply to author
Forward
0 new messages