vba 如何获取功能区自定义选项卡 ID?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/615482/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 10:16:06  来源:igfitidea点击:

How to get Ribbon custom Tabs IDs?

vbaribbonpowerpoint-vba

提问by Ubalo

I am working with a Custom Ribbon in Power Point, I need to iterate through all tabs and get the ID of them.

我正在使用 Power Point 中的自定义功能区,我需要遍历所有选项卡并获取它们的 ID。

The Ribbon contains Tabs added from different projects (C++, C#) as addins and I don't know their IDs. I am using VBA to handle the events fired from the Ribbon.

功能区包含从不同项目(C++、C#)添加的选项卡作为插件,我不知道它们的 ID。我正在使用 VBA 来处理从功能区触发的事件。

How do I do to get the ID from all tabs in the Ribbon using VBA?

如何使用 VBA 从功能区中的所有选项卡获取 ID?

Thanks in advance.

提前致谢。

回答by Alain

The Ribbon is accessed using CommandBars("Ribbon") which returns an IAccessible object. You access tabs by using

使用 CommandBars("Ribbon") 访问功能区,它返回一个 IAccessible 对象。您可以通过使用访问选项卡

AccessibleChildren _
            Lib "oleacc.dll" _
                (ByVal paccContainer As Object, _
                 ByVal iChildStart As Long, _
                 ByVal cChildren As Long, _
                       rgvarChildren As Variant, _
                       pcObtained As Long) _
            As Long

This will fill an array with a list of all child elements (tabs) which are also IAccessible objects. The ID's you get are strings, and you can iterate through the children of each one to get submenu items and so on.

这将使用所有子元素(选项卡)的列表填充数组,这些子元素也是 IAccessible 对象。您获得的 ID 是字符串,您可以遍历每个 ID 的子项以获取子菜单项等。

It's quite complicated, so the best way to get this done would be to work from an example. Lucky for you there is a gleaming example here: http://www.wordarticles.com/Shorts/RibbonVBA/RibbonVBADemo.htm

它非常复杂,因此完成此操作的最佳方法是从示例中工作。幸运的是,这里有一个闪闪发光的例子:http: //www.wordarticles.com/Shorts/RibbonVBA/RibbonVBADemo.htm

ribbon tabs

功能区标签

Pore through the code on that one.

仔细阅读那个代码。