Programatically configure Office 2010 Word Ribbon via VBA

13,353

Solution 1

You can manipulate a Ribbon tab and its controls using VBA, but you cannot create one. Not with the Object Model anyway. The best you could do - somehow - is to get some kind of OPC dll (like an ActiveX component) that handles opening/relationships/closing of OPC documents (like .docx documents) and old school MSXML for creating a ribbon definition and adding it to the package.

Solution 2

If your UI is static, i.e. you don't need to programatically change the behavior of, or add/remove UI elements on the fly, you can define a customUI within a macro-enabled template. You can use your VBA functions as call-backs for the UI elements defined in the XML.

Have a look at this guide. In a nutshell, you define a customUI\customUI14.xml file within the .dotm archive. This XML describes your custom ribbon elements using this schema.

This definitely works for Word templates (.dotm files). I think a similar approach works for any OOXML format.

Solution 3

Have a look at this blog post for Excel

http://www.xtremevbtalk.com/showthread.php?t=265636

and this one for Word

http://www.wordarticles.com/Shorts/RibbonVBA/RibbonVBADemo.htm

Share:
13,353
Maate
Author by

Maate

Updated on June 04, 2022

Comments

  • Maate
    Maate almost 2 years

    Is it possible to configure a Ribbon (e.g. adding a tab etc.) in Office 2010 programatically via VBA? I.e. by writing VBScript code in a macro.

    Br. Morten