vba 如何向 PowerPoint 2010 添加调用宏的选项卡
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3867400/
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
How to add tabs to PowerPoint 2010 that call macros
提问by JoelCool
I have created a pptm file with macros that open certain pptx templates. I then created a new tab with buttons for opening the files. I attached the macros I created to those buttons. All works great as long at my pptm file is open. But after I save it as a ppam file and install it as an add-in it no longer works. It seems the macros don't come along and the buttons are still trying to reference the macros via the pptx name.
我创建了一个 pptm 文件,其中包含打开某些 pptx 模板的宏。然后我创建了一个带有用于打开文件的按钮的新选项卡。我将我创建的宏附加到这些按钮上。只要我的 pptm 文件打开,一切都很好。但是在我将其保存为 ppam 文件并将其安装为加载项后,它不再起作用。宏似乎没有出现,按钮仍在尝试通过 pptx 名称引用宏。
Does anyone know a simple way to create a custom tab to launch predefined templates? Or load macros by default like Word does? Or fix my situation above? The only alternative I see is an add-in that will only show up under the Add-In's tab.
有谁知道创建自定义选项卡以启动预定义模板的简单方法?还是像 Word 那样默认加载宏?或者解决我上面的情况?我看到的唯一替代方法是仅显示在“加载项”选项卡下的加载项。
回答by Todd Main
Are you manually creating the ribbon with the buttons? I use the Custom UI Editor Tooland it works like a charm.
您是否使用按钮手动创建功能区?我使用自定义 UI 编辑器工具,它就像一个魅力。
Just create any macro in your .pptm, like this:
Sub SayHello(ByVal control As IRibbonControl) MsgBox "hello" End Sub
The
(ByVal control As IRibbonControl)
part is important.Then save and close your .pptm.
Open the Custom UI Editor Tool. From that tool, click Openfrom the Filemenu and navigate to your .pptm and open it.
On the Insertmenu, click Office 2010 Custom UI Part. This will create a new XML document that will be inserted into your .pptm.
You can then use sample snippets to start creating your ribbon, but the simplest is just from the Insert | Sample XMLmenu, just click on Custom Tab. This will insert:
<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui"> <ribbon startFromScratch="false"> <tabs> <tab id="customTab" label="Custom Tab"> <group id="customGroup" label="Custom Group"> <button id="customButton" label="Custom Button" imageMso="HappyFace" size="large" onAction="Callback" /> </group> </tab> </tabs> </ribbon> </customUI>
Where you see
Callback
in afteronAction
, replace it with the name of your macro. In our example above, it isSayHello
, so it should now look likeonAction="SayHello"
.Click Saveand then close the Custom UI Editor Tool.
Open your .pptm in PowerPoint and test that a tab called Custom Tabhas been created. Navigate to it and click on the happy face button. You should now get a message box.
Go to the Backstage by clicking on Fileand click Save As...and then choose as the file type PowerPoint Add-in (*.ppam) and save it in any location. Note the location.
Go to File | Options | Add-inand then select PowerPoint Add-insfrom the Managedropdown at the bottom of the dialog. Then click Go. Click **Add New...* and add your add-in from the location you saved it.
Close PowerPoint and reopen it. The Custom Tabribbon should be there. Click on the happy face icon to run your
SayHello
macro.
只需在您的 .pptm 中创建任何宏,如下所示:
Sub SayHello(ByVal control As IRibbonControl) MsgBox "hello" End Sub
该
(ByVal control As IRibbonControl)
部分是很重要的。然后保存并关闭您的 .pptm。
打开自定义 UI 编辑器工具。从该工具中,单击“文件”菜单中的“打开”并导航到您的 .pptm 并将其打开。
在插入菜单上,单击Office 2010 自定义 UI 部件。这将创建一个新的 XML 文档,该文档将插入到您的 .pptm 中。
然后,您可以使用示例片段开始创建功能区,但最简单的方法是从Insert | 示例 XML菜单,只需单击Custom Tab。这将插入:
<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui"> <ribbon startFromScratch="false"> <tabs> <tab id="customTab" label="Custom Tab"> <group id="customGroup" label="Custom Group"> <button id="customButton" label="Custom Button" imageMso="HappyFace" size="large" onAction="Callback" /> </group> </tab> </tabs> </ribbon> </customUI>
Callback
在 after 中看到的地方onAction
,将其替换为您的宏的名称。在我们上面的例子中,它是SayHello
,所以它现在应该看起来像onAction="SayHello"
。单击保存,然后关闭自定义 UI 编辑器工具。
在 PowerPoint 中打开 .pptm 并测试是否已创建名为“自定义选项卡”的选项卡。导航到它并单击笑脸按钮。您现在应该会收到一个消息框。
单击“文件”转到“后台”,然后单击“另存为...”,然后选择 PowerPoint 加载项 (*.ppam) 作为文件类型并将其保存在任何位置。注意位置。
转到文件 | 选项 | 加载项,然后从对话框底部的管理下拉列表中选择PowerPoint 加载项。然后点击前往。单击 **Add New...* 并从您保存的位置添加您的加载项。
关闭 PowerPoint 并重新打开它。在自定义标签色带应该在那里。单击笑脸图标以运行您的
SayHello
宏。
The only thing you'll need to do beyond this is to customize your macros and ribbon controls they way you need them and for what you want them to do. Check out this link for more info: Customizing the 2007 Office Fluent Ribbon for Developers
除此之外,您唯一需要做的就是按照您需要的方式自定义您的宏和功能区控件以及您希望它们做什么。查看此链接了解更多信息:为开发人员自定义 2007 Office Fluent Ribbon