加载Excel加载项 [英] Load Excel add-in

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

问题描述

我尝试过:

$sAddIn = "H:\prog\essxleqd.xla"
$oExcel = ObjCreate("Excel.Application")
$oExcel.Visible = 1
$oExcel.WorkBooks.Add
$oAddIn = $oExcel.AddIns.Add($sAddIn)
$oAddIn.Installed = True
$oExcel.WorkBooks.Open("H:\Balance_Inquiry.xls")

当我这样做时:

Run('"c:\pathtoexcel\excel.exe" "c:\pathtoaddin\addin.xla"')

它将起作用.但是我更喜欢前一种解决方案,因为我需要两个不同的加载项.

It will work. But I prefer the former solution because I need two different add-ins.

$sAddIn = "H:\prog\essxleqd.xla"
$oExcel = ObjCreate("Excel.Application")
$oExcel.Visible = 1
$oExcel.WorkBooks.Add
$oAddIn = $oExcel.AddIns.Add($sAddIn)
$oAddIn.Installed = False
$oAddIn.Installed = True
$oExcel.WorkBooks.Open("H:\Balance_Inquiry.xls")

这似乎可以解决问题.第一次安装并工作.之后没有.即使安装了它,它也不会第二次执行.也许有人可以解释或提供更优雅的解决方案?

This seems to do the trick. First time it got installed and worked. Afterwards it didn't. Even when it is installed it doesn't execute the second time. Maybe someone can explain or provide a more elegant solution?

推荐答案

确实是奇怪的问题.似乎该插件仅在安装时会执行其操作?这不是Excel插件应具有的行为,这就是为什么在尝试使其自动化时看到奇怪的行为的原因.

Strange problem indeed. It seems that the addon will only do its operations when you install it? That is not how Excel addons should behave, and that is why you are seeing strange behavior when trying to automate it.

如果需要重新安装附加组件才能正常工作,那么实际上唯一的解决方案是重新安装附加组件.

If the addon needs to be reinstalled to work, then indeed the only solution is to reinstall the addon.

$oAddIn.Installed = False
$oAddIn.Installed = True

如果这是您或您自己公司中的某个人编写的插件,那么您可能希望在插件本身中识别问题.我可以向您保证,正常的操作模式会很好. :))

If this is an addon that is written by you or someone in your own business, then you might want to identify the problem in the addon itself. I can safely assure you that the normal mode of operation works well. :))

作为奖励提示,您可能需要执行以下操作:

As a bonus tip, you might want to do this:

$oAddIn = $oExcel.AddIns.Add($sAddIn, True)

如果有必要,它将把文件复制到适当的位置,否则将被单独保留.

It will copy the file to the appropriate location if that is necessary, otherwise it is left alone.

这篇关于加载Excel加载项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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