PowerPoint VBA - 关闭时保留自定义命令栏设置

发布于 2024-09-30 07:17:47 字数 560 浏览 1 评论 0原文

我为 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

勿忘心安 2024-10-07 07:17:47

最好做您正在做的事情 - 在 PowerPoint 关闭时删除您的 CommandBar。这样,即使出现错误,您的加载项也不会在 UI 中留下无法正常工作的痕迹。

不过,为了管理状态,许多人使用 GetSettingSaveSetting 来读取/写入 VB/VBA 程序注册表中的沙盒区域。在此 页面GetSettingSaveSettingGetAllSettingsDeleteSetting >。您可以使用它们在 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 and SaveSetting 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文