Replacing Word's Open File Dialog in a COM Add-in - com

I'm writing a Word COM Add-in that replaces the Open & Save dialogs with my own.
For the save dialog, I'm handling the documentBeforeSave event from the application events. This works fine.
For the open dialog, there is no such event, so I'm currently handling the onClick of the Open... menu item, canceling the default handling. This works ok if the user indeed uses this menu item, but if the user presses CTRL-O in stead they still get the original dialog.
Is there a better way to hook into this dialog? And if there isn't, is there a way to elegantly handle this keypress, or should I resolve to keyboard hooks?
Note: The add-in should eventually work on Office 2003, 2007 and 2010, but using different code-paths on different targets is of course perfectly fine. I am interested in any solutions on any version.

In Word 2007+, this turns out to be incredibly simple to implement. Simply repurpose the FileOpen command through the ribbon XML
<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui">
<commands>
<command idMso="FileOpen" onAction="doOpen" />
</commands>
...
The doOpen method then has two parameters, the second being an in/out parameter allowing you to cancel the event.
For previous version of Office, I've never implemented a fully bulletproof solution.

Related

synchronize Outlook Ribbon togglebutton with registry settings in VB.Net for an Add-In

I am building an Outlook Add-In in Visual Basic and I have a togglebutton in the ribbon that controls whether a setting is on or off. This settings is saved and retrieved using "GetSettings" and "SaveSetting" which saves information to the Windows Registry (to my understanding). I want the togglebutton the correspond to changes made to that setting as it can be changed in other places than just the togglebutton. My problem would be solved if I could access the value of the togglebutton and setting it manually but as I have understood it: I cannot access it as I am building my ribbon in XML. I have not been able to find a solution to this, can anyone help?
Side note: If I add my togglebutton to the taskbar in Outlook and from there toggle the settings, the togglebutton in the ribbon doesn't change to "pressed" mode. Perhaps this is something that can be fixed with any provided solution from anyone :)
You need to use IRibbonUI.Invalidate or for a single control you may use the IRibbonUI.InvalidateControl method to get your ribbon callbacks invoked for updating the cached values according to the state loaded from settings.
For example, if an add-in implements the getPressed callback procedure for a toggle button, the function is called once, the state loads, and then if the state needs to be updated, the cached state is used instead of recalling the procedure. This process remains in place until the add-in signals that the cached values are invalid by using the Invalidate method, at which time, the callback procedure is again called and the return response is cached. The add-in can then force an immediate update of the UI by calling the Refresh method (VSTO).
You can read more about the Fluent UI (aka Ribbon UI) in the following articles:
Customizing the 2007 Office Fluent Ribbon for Developers (Part 1 of 3)
Customizing the 2007 Office Fluent Ribbon for Developers (Part 2 of 3)
Customizing the 2007 Office Fluent Ribbon for Developers (Part 3 of 3)
Do not rely on the button to store the state for you - whenever it changes, it is your responsibility to refresh the Ribbon (by calling IRibbonUI.Invalidate), which will cause Outlook to invoke your callback on the toggle button to determine its state. You just need to store the appropriate state in your code.

Can I change icon of office addin command button on completion of any event

Here I am trying implement an email tracking system through office addin command button and I want to change the button-icon immediately when track event is completed.Please give your opinion.
We don't support runtime changes of the button icon. But it's a good idea. Please suggest this at Office Developer User Voice.

Keep changes to office ribbon local to file?

I have a presentation that needs to be regularly updated. To facilitate this quickly I have written a simple form in VBA which I would like to be accessible from the ribbon (or via a button in editor mode).
However I do not want the button in the ribbon to be visible in other Power point documents.
Is it possible to stop customizations from being applied globally?
Thanks in advance
XML ribbon customizations in a PPTM file are only visible when that file is open and has focus. It sounds like this is what you'd want to do ... store the VBA and RibbonX code in the file you want to work with.
If the XML ribbon customizations are in an add-in (ie. PPAM) that's loaded, the customizations will be present for any open file.
#Cilvic has a good point (thanks!). If you're adding customizations to the Ribbon or QAT via the built-in customization feature, these will also be there whenever PPT is open. You can't make them appear only when a certain file is open.
Where are your customizations (and are you in fact using XML or are you creating command bars)?

Word Add-in - find if dialog has focus?

I am writing a word add-in in VB .NET (using Add-in Express, but I don't think that's relevant).
I have created shortcuts, but I only want them to take effect if the document itself is in focus, not a dialog - for example, "Find and replace" or any other.
How do I determine if a dialog has focus?
The "Selection" property of the application points to the selection in the document, even if a dialog is currently selected. I can't find any "HasFocus"-equivalent property anywhere either. I'm running out of ideas :o)
Thanks!
This workaround worked for me:
My add-in keeps a reference to the handle of the most recently activated Word window, by using the GetActiveWindow API during the WindowActivate event of the Word application. This is necessary since, up until Office 2013, the Window object does not expose a handle property.
When a shortcut is triggered, I compare that to the handle of the currently active window, using the same API. If they don't match, I simply don't proceed :o)

Outlook 2007 Ribbon and MVP

I'm working on outlook 2007 VSTO Addin.I have added a Ribbon with a button. I am trying to raise an event on button click.On NewInspector event of Application.Inspectors collection I should be able to hook on to this ribbon event in the Presenter.
The questions is how to get hold of Ribbon of Inspector opened. I tried Globals.Ribbons.MyRibbon to do so.Strangely it works only for the first inspector. I also tried Globals.Ribbons[inspector].MyRibbon.
Looks like when NewInspector is created the Ribbons Collection has 0 Items and Ribbon load happen only after NewInspector event handler is executed.
Is there any event to know when a ribbon loads OR Is there any alternative way ,where i can keep the business logic in Presenter instead of having it in ribbon view.
The answer is with much effort..
As far as I can tell the ribbon is not exposed through vsto or com interop, it is also stateless, so the ribbon will be loaded once no matter how many inspectors are shown.
It took me a long time to gracefully solve this issue, and it is pretty complex code. I also should mention that I chose to tackle the problem using ribbon XML rather than the designer, I found the designer too restrictive.
The guts of it is you have to create a custom IRibbonExtensibility implementation, then rewrite the callbacks in the ribbon XML, so they will callback to methods on your IRibbonExtensibility impl.
You then have to handle the loaded event, and the new inspector event so you can relate the two.
There is actually a lot more to it and you can check out my code in the VSTO contrib project.
http://vstocontrib.codeplex.com/SourceControl/changeset/view/b35f26fdca15#src%2fOutlook.Utility%2fRibbonFactory%2fRibbonFactory.cs
If you are building a MVP framework for VSTO drop me an line as I would be interested to see what you are doing.