0
votes

In my Word VSTO Ribbon AddIn, I need to detect when the user changes the current section's page orientation using Word's native function.

So, when a user goes to Word > Layout (Ribbon Tab) > Orientation > Portrait/Landscape

I need to catch this event in VSTO code for the active document so I can handle it and make some document adjustments in code.

1

1 Answers

1
votes

Unfortunately, Word provides no event that will trigger when this action is taken. So the only way you can "trap" it as it happens is to customize the Ribbon using RibbonXML (the Designer can't do what you need).

The Ribbon XML would need to hide the built-in PageSetup group and you'd need to define a custom Group (which you can label Page Setup) containing the same buttons as the built-in group. For all except Orientation you can use the idMso values for the buttons.

For Orientation, use a menu button with your own id value, but you can use the idMso for the built-in image, so that it lookds the same. Define the Portrait and Landscape menu items with call-backs that perform the default actions (assuming you want those) and notify the rest of your code in the way you require.

The three-part article Customizing the Office 2007 Office Fluent Ribbon for Developers contains all the necessary information, but you'll need to piece it together. There's also some VSTO documentation on working with the Ribbon. And there are a lot of examples around, if you search.