2

I wish to create a Microsoft Word add-in for use by others in my office which will give them access to a few macros that will increase productivity and possibly prevent the odd mistake from happening.

The bit that I cannot work out is how I can get this add-in to automatically create a new tab and display its various macros as buttons on this tab. All I can find is information on how to manually customise the ribbon interface or import an existing customisation. These methods will not work as I have co-workers who already have customised their ribbon interface and thus are unwilling to have my work overwrite theirs.

As far as I can tell there are no VBA methods that directly manipulate the ribbon interface so I'm slightly stumped. I do believe that this is possible as a co-worker showed me a document which seemed to do this. Could anyone give me a pointer in the right direction?

cxw
  • 16,685
  • 2
  • 45
  • 81
MrPopinjay
  • 179
  • 4
  • 14

1 Answers1

2

Tutorials

When you'll have working addin with ribbon and custom buttons. Use this code to run macro from button event handler:

    /// <summary>
    /// Runs macro
    /// </summary>
    /// <param name="oApp">Application object</param>
    /// <param name="oRunArgs">Macro arguments (first macro name)</param>
    public static void RunMacro(object oApp, object[] oRunArgs)
    {
        oApp.GetType().InvokeMember("Run",
        System.Reflection.BindingFlags.Default |
        System.Reflection.BindingFlags.InvokeMethod,
        null, oApp, oRunArgs);
    }
tinamou
  • 2,282
  • 3
  • 24
  • 28
  • Thank you for your reply, I shall start reading when I have some downtime and get back to you if I make any progress. Wish me luck! – MrPopinjay Jun 14 '13 at 09:47
  • Good luck! May the time be with ;) – tinamou Jun 15 '13 at 18:27
  • This is all looking rather fiddly and expensive. This might not be viable after all. :( – MrPopinjay Jun 17 '13 at 11:14
  • You may try this approach: http://mohammedkb.wordpress.com/2010/09/14/customize-excel-ribbon-and-make-your-macros-default-commands-2/ (after customizing your ribbon sharing it with others can be done by:(comments below post) "under Options/Customize Ribbon, export your customized ribbon by hitting the Import/Export button (Export all customizations). You need, then, to share this ribbon file to others and have each one import it the same way (Import customization file). The other thing that you may need to do is to save the macro as Add-in in their Excel App as explained in the blog." – tinamou Jun 17 '13 at 13:08
  • Yes, but as I said in the post this is not a viable solution as people already have customised ribbons that they will not be willing to sacrifice for my customisation. I need a way of automatically modifying an existing customisation... Unless I purchase Visual Studio I believe this will be a real pain to achieve. – MrPopinjay Jun 17 '13 at 14:50
  • then your additional step is editing each co-worker export file (it is XML) and add your definition of custom tab and re-import edited definition – tinamou Jun 18 '13 at 16:03
  • Yes, that seems to be what I'm looking at. It's a little frustrating, I wanted a more automated solution. Thank you for your help! – MrPopinjay Jun 19 '13 at 09:21