如何在 VBA 中创建一个在加载相应的加载项时执行的 Sub?
我在 VBA 中有一个子例程,当我们打开 PowerPoint 演示文稿时执行该子例程,但我想在加载外接程序时执行该子例程。
我怎样才能做到这一点?
I have a subroutine in VBA that is executed when we open a PowerPoint presentation but I want to execute that Sub when an Add-in is loaded instead.
How can I do that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果我理解正确,您有一个加载项,您希望仅在加载加载项时运行现有幻灯片的子例程。
如果是这样,以下是有关如何执行此操作的说明:
创建幻灯片,将其另存为
“Presentation3.pptm”(启用宏
2007年PPT)。打开VBE并输入
在以下代码中:
立即创建一个加载项。创建另一个
甲板,转到VBE并将其放入
任何模块:
现在将此加载项另存为 PowerPoint
加载项 (.ppam)。安装并加载
插件(如果它再次尝试卸载/加载
不触发),你应该有
在活动上创建的文本框
演示文稿。
注意#2:
Application.Run (p.Name & "!AddText")
。表示名称(包括扩展名)和“!”需要使用子例程的名称才能在另一个演示文稿中运行宏。If I'm understanding you correctly, you have an add-in that you want to run the sub-routine of an existing slide deck only when the addin is loaded.
If so, here are instructions on how to do this:
Create a slide deck, save it as
"Presentation3.pptm" (macro-enabled
PPT for 2007). Open the VBE and put
in the following code:
Create an add-in now. Create another
deck, go to the VBE and put this in
any module:
Now save this add-in as a PowerPoint
Add-in (.ppam). Install and load the
addin (try unload/load again if it
doesn't trigger) and you should have
a textbox created on the active
presentation.
Notice in #2 :
Application.Run (p.Name & "!AddText")
. The presenation name (including extention) and "!" with the sub routine's name are required to run a macro in another presentation.