在使用CreateObject启动Excel后,UFT – Excel加载项无法安装

我通过UFT自动化Excel插件。 我使用CreateObject来启动excel:

Set oExcel = CreateObject("Excel.Application") oExcel.Workbooks.Add oExcel.Visible = True 

在继续之前,我想确保我的加载项被正确安装。 所以我这样做:

 For K = 1 To oExcel.AddIns.Count Step 1 If Trim(oExcel.AddIns.Item(K).Name) = "AddInName.xll" Then If oExcel.AddIns.Item(K).Installed Then oExcel.AddIns.Item(K).Installed = False wait (2) oExcel.AddIns.Item(K).Installed = True wait (2) If oExcel.AddIns.Item(K).IsOpen Then 'Reporter.ReportEvent micPass, "Add_In Successful", "Successfully loaded Add_In" Exit For End If End If End If Next 

现在,在Window 7 + Office 2010configuration中,这一直没有任何问题。 不过,我公司最近转移到了Windows 10 + Office 2016环境,下面一行开始抛出错误:

 oExcel.AddIns.Item(K).Installed = True 

之前的行(设置安装状态为false)工作正常。 被抛出的错误是:

插件<>所需的Ribbon / COM插件助手无法注册。 这是一个意外的错误。 ExcelDna.Integration信息:4:LoadComAddInexception:System.Reflection.TargetInvocationException:exception已被调用的目标引发。 —> System.Runtime.InteropServices.COMException:类未注册(exception来自HRESULT:0x80040154(REGDB_E_CLASSNOTREG))

我曾经尝试过的东西:

  1. 我将上面的代码保存为Windows 10机器上的vbs文件,并试图执行它。 它工作得很好。
  2. 我试图启动Excel作为excel.exe而不是CreateObject。 加载项加载完全正常。
  3. 我试图在开始testing之前打开Excel,并使用GetObject来获取Excel对象。 在这种情况下加载项加载完美。

那么UFT中的CreateObject会发生什么? 显然这是UFT这是造成问题,因为它通过独立的VBS文件工作正常!

任何帮助非常感谢..谢谢!