开发者

Programatically configure Office 2010 Word Ribbon via VBA

Is it possible to configure a R开发者_Go百科ibbon (e.g. adding a tab etc.) in Office 2010 programatically via VBA? I.e. by writing VBScript code in a macro.

Br. Morten


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.


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜