PowerPoint VBA - 关闭时保留自定义命令栏设置
我为 2003 版及更早版本开发了一个 PowerPoint 插件,可在安装时生成自定义命令栏/工具栏。
在卸载时删除此命令栏没有任何困难,但由于它使用 Auto_Close 事件来执行此操作,因此每次 PowerPoint 关闭时它也会删除工具栏,从而阻止用户永久自定义命令栏的位置。
我尝试通过检查加载项是否已注册或加载来进行条件删除,但 Auto_Close
似乎在任何卸载或取消注册之前运行。
关于如何仅在卸载加载项时删除命令栏有什么想法吗?
Sub Auto_Close()
Dim pptAddin As AddIn
For Each pptAddin In AddIns
If pptAddin.Name = "AddInName" And _
pptAddin.Registered <> msoTrue Then
Application.CommandBars("CommandBarName").Delete
End If
Next
End Sub
I have developed a PowerPoint add-in for versions 2003 and earlier that generates a custom commandbar/toolbar on install.
I have no difficulty removing this commandbar on uninstall, but because it uses the Auto_Close
event to do so, it also deletes the toolbar every time PowerPoint closes, preventing the user from permanently customizing the commandbar's position.
I've tried a conditional delete by checking if the add-in is registered or loaded, but Auto_Close
seems to run before any unloading or deregistration.
Any ideas on how to delete the commandbar ONLY when the add-in is being uninstalled?
Sub Auto_Close()
Dim pptAddin As AddIn
For Each pptAddin In AddIns
If pptAddin.Name = "AddInName" And _
pptAddin.Registered <> msoTrue Then
Application.CommandBars("CommandBarName").Delete
End If
Next
End Sub
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最好做您正在做的事情 - 在 PowerPoint 关闭时删除您的 CommandBar。这样,即使出现错误,您的加载项也不会在 UI 中留下无法正常工作的痕迹。
不过,为了管理状态,许多人使用
GetSetting
和SaveSetting
来读取/写入 VB/VBA 程序注册表中的沙盒区域。在此 页面:GetSetting
、SaveSetting
、GetAllSettings
、DeleteSetting
>。您可以使用它们在 PowerPoint 实例之间管理外接程序的 CommandBar。使用起来相对简单 - 这里有一个 Excel 教程,同样适用到 PowerPoint。It's a good idea to do what you're doing - deleting your CommandBar when PowerPoint closes. That way if there is ever an error, your add-in doesn't leave artifacts in the UI that don't work.
For managing state though, many folks use
GetSetting
andSaveSetting
for reading/writing to a sandboxed area in the Registry for VB/VBA programs. Look up the following functions on this page:GetSetting
,SaveSetting
,GetAllSettings
,DeleteSetting
. You can use these to manage your add-in's CommandBar between PowerPoint instances. It's relatively simple to use - here's a tutorial for Excel that would apply equally to PowerPoint.