以编程方式实例化 Excel 时加载插件 [英] Loading addins when Excel is instantiated programmatically

查看:28
本文介绍了以编程方式实例化 Excel 时加载插件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 VBA 创建一个新的 Excel 实例:

I am trying to create a new instance of Excel using VBA using:

Set XlApp = New Excel.Application

问题是这个新的 Excel 实例并没有加载我正常打开 Excel 时加载的所有加载项...Excel Application 对象中是否有任何内容用于加载所有用户指定的加载项?

The problem is that this new instance of Excel doesn't load all the addins that load when I open Excel normally...Is there anything in the Excel Application object for loading in all the user-specified addins?

我不是要加载特定的加载项,而是让新 Excel 应用程序的行为就像用户自己打开它一样,所以我真的在寻找用户选择的所有加载项的列表通常在打开 Excel 时加载.

I'm not trying to load a specific add-in, but rather make the new Excel application behave as though the user opened it themself, so I'm really looking for a list of all the user-selected add-ins that usually load when opening Excel.

推荐答案

我再次研究了这个问题,Application.Addins 集合似乎包含了 Tools->Addins 菜单中列出的所有加载项,并带有一个布尔值说明是否安装了插件.所以现在似乎对我有用的是循环遍历所有插件,如果 .Installed = true 那么我将 .Installed 设置为 False 并返回到 True,这似乎可以正确加载我的插件.

I looked into this problem again, and the Application.Addins collection seems to have all the addins listed in the Tools->Addins menu, with a boolean value stating whether or not an addin is installed. So what seems to work for me now is to loop through all addins and if .Installed = true then I set .Installed to False and back to True, and that seems to properly load my addins.

Function ReloadXLAddins(TheXLApp As Excel.Application) As Boolean

    Dim CurrAddin As Excel.AddIn

    For Each CurrAddin In TheXLApp.AddIns
        If CurrAddin.Installed Then
            CurrAddin.Installed = False
            CurrAddin.Installed = True
        End If
    Next CurrAddin

End Function

这篇关于以编程方式实例化 Excel 时加载插件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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