打开 Powerpoint 演示文稿时如何自动执行宏? [英] How to auto execute a macro when opening a Powerpoint presentation?

查看:45
本文介绍了打开 Powerpoint 演示文稿时如何自动执行宏?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个非常基本的问题,但在互联网上找不到答案.
在 Powerpoint 2010 中,我有一个宏,我希望每次打开 Powerpoint 文档时都执行该宏.如何做到这一点?

谢谢!

解决方案

虽然 Auto_Open 不在 PowerPoint 演示文稿中运行,但您可以伪造它.将 CustomUI 部件添加到演示文稿,然后使用 CustomUI OnLoad 回调在演示文稿打开时运行代码.CustomUI 部分只需要 CustomUI 标签.

从此处获取自定义 UI 编辑器:

现在输入一些简单的 RibbonX 代码,如下所示:

<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui"onLoad="MyOnloadProcedure" ></customUI>

现在编写你的打开过程:

Sub MyOnloadProcedure()MsgBox "你好"结束子

如果加载项中同时具有此过程和 Auto_Open 过程,则 Auto_Open 首先运行.

完全披露:虽然我想使用这种方法并在 Excel 中使用过,但我一直等到我在 PPT Alchemy 网站上第一次遇到它:在 PowerPoint 打开时运行代码.

I have a pretty basic question, but could not find the answer on internet.
In Powerpoint 2010, I have a macro that I would like to be executed everytime the Powerpoint document is opened. How to achieve this ?

Thanks !

解决方案

While Auto_Open doesn't run in a PowerPoint presentation, you can fake it. Add a CustomUI part to the presentation, then use the CustomUI OnLoad callback to run code when the presentation opens. The CustomUI part needs no more than just the CustomUI tags.

Get the Custom UI Editor from here: http://openxmldeveloper.org/articles/customuieditor.aspx

Open the presentation in the Custom UI Editor. Insert a CustomUI part from the Insert menu:

Now enter some simple RibbonX code, like this:

<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui" 
onLoad="MyOnloadProcedure" >
</customUI>

Now write your on-open procedure:

Sub MyOnloadProcedure()
    MsgBox "Hello"    
End Sub

If you have both this and the Auto_Open procedure in an add-in, Auto_Open runs first.

Full disclosure: while I thought of using this approach and have used it in Excel, I waited until I first encountered it on the PPT Alchemy web site: Run Code When PowerPoint Opens.

这篇关于打开 Powerpoint 演示文稿时如何自动执行宏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆