سؤال

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?

هل كانت مفيدة؟

المحلول

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.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top