Load Excel add-in

丶灬走出姿态 提交于 2019-12-08 09:29:06

问题


I tried:

$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")

When I do:

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?


回答1:


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.



来源:https://stackoverflow.com/questions/4669201/load-excel-add-in

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!