Hello Dave,
Thanks for clarifying about this, so based on my understanding, we are
trying to change the ribbon UI dynamically by specifying another ribbon xml
file, right?
Far from my researching, I did not find any way to unload and reload the
ribbon customization xml file dynamically. If we want to unload and reload
the ribbon, at least we have to unload and reload our Add-in. Supposed that
we choose this way to go, I think another Add-in should be necessary to
control our Add-in's loading and unloading. But that is too bad. Thus,
based on your requirement, may I suggest we use the following workaround
instead?
We can put both of the two tabs in the same customization xml file. We
define the getVisible callback function for these tabs. Whenever we want to
show/hide a tab, we call ribbon.Invalidate. So the getVisible callback will
be called, and we get chance to set the table's visible there.
Here are codes work on my side,
customUI.xml,
<?xml version="1.0" encoding="UTF-8"?>
<customUI onLoad="Ribbon_Load"
xmlns="
http://schemas.microsoft.com/office/2006/01/customui">
<ribbon>
<tabs>
<tab id="tab1" label="tab1" getVisible ="GetVisible" >
<group id="group1" label="group1">
<button id="button1" label="button1" />
</group>
</tab>
<tab id="tab2" label="tab2" getVisible ="GetVisible">
<group id="group2" label="group2">
<button id="button2" label="button2" />
</group>
</tab>
</tabs>
</ribbon>
</customUI>
and the shared add in codes,
public IRibbonUI ribbon;
private Word.Application applicationObject;
private object addInInstance;
private string visibleTab;
public string GetCustomUI(string RibbonID)
{
using (StreamReader resourceReader = new
StreamReader(@"D:\customUI.xml"))
{
if (resourceReader != null)
{
return resourceReader.ReadToEnd();
}
}
return null;
}
public void Ribbon_Load(IRibbonUI ribbonUI)
{
visibleTab = "tab1";
this.ribbon = ribbonUI;
}
public bool GetVisible(IRibbonControl control)
{
if (control.Id == visibleTab)
{
return true;
}
else
{
return false;
}
}
public void OnConnection(object application,
Extensibility.ext_ConnectMode connectMode,
object addInInst, ref System.Array custom)
{
applicationObject = application as Word.Application;
addInInstance = addInInst;
applicationObject.WindowSize += new
Microsoft.Office.Interop.Word.ApplicationEvents4_WindowSizeEventHandler(appl
icationObject_WindowSize);
}
void applicationObject_WindowSize(Microsoft.Office.Interop.Word.Document
Doc, Microsoft.Office.Interop.Word.Window Wn)
{
if (visibleTab == "tab1")
{
visibleTab = "tab2";
}
else
{
visibleTab = "tab1";
}
this.ribbon.Invalidate();
}
I use the Application.WindowSize event as a trigger to switch between tab1
and tab2 in the above codes. Please let me know if this suggestion works
for your scenario. Any future questions, please feel free to post and I
will do my best to help.
Best regards,
Ji Zhou (
[email protected], remove 'online.')
Microsoft Online Community Support
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://support.microsoft.com/select/default.aspx?target=assistance&ln=en-us.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.