I have implemented a ribbon that its buttons are enabled/disabled according to document file path. The problem is that when I open a second document, the Ribbon_Load doesn't get called again and the buttons have the values of the first opened document. Why is this happening and how can make Ribbon_Load to get called every time a new item is called?
Thank you
Ribbon_Load
only is called when the add-in first loads into an Office application. When you open additional files the add-in is not loaded again, even if the document appears in a separate window. So Ribbon_Load is not called again.
You can use the DocumentOpen
event to trigger the Ribbon callbacks that should execute. (Exactly how you do that depends on whether you use the Ribbon Designer or Ribbon XML.) Note that if you want each document window to reflect different settings in the Ribbon you'll probably also need to work with additional events, such as NewDocument
, DocumentClose
and WindowActivate
.
You may find the following article on MSDN useful, even though it was written for Custom Task Panes the logic required for managing multiple Ribbons is pretty much the same: Managing Task Panes in Multiple Word and InfoPath documents.