Creating an MS Office add-in that adds a new tab to the ribbon interface and presents macros to the user as buttons on this tab

StackOverflow https://stackoverflow.com/questions/17085196

Question

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?

Was it helpful?

Solution

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);
    }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top