在安装我的外挂程序后,在Excel中调用“1”参数“…”打开“”的exception

我一直在试图自动化的Excel自动化,安装我们公司的插件在Excel中,然后加载库文件(library.xlsm,包含库macros子程序和函数)。 在每次testing之后,我加载相应的test.xlsm文件并执行macros。 所有这一切,我正在使用PowerShell(V3)。 我的脚本在一台机器上被调用,并在另一台远程机器上执行。

这是我如何安装我的插件:

kill -processname excel $Release1RootDir = $workspace + "\Release1" $release1Path = Get-ChildItem -Force $release1RootDir if($release1Path -eq $Null) { echo "Error: No sub-folder found having MyAddin Installer inside "$release1RootDir } else { $release1 = $release1Path.name.replace('_', '.') $ExcelAddinInstaller = ($release1Path.FullName + "\MyAddin.msi") $ExcelAddinTargetDir = ($Release1Path.FullName) $msiexecPath = "msiexec.exe" if(Test-Path -Path $ExcelAddinInstaller){ echo "Version for MyAddin inside Release1: "$Release1 $proc = Start-Process $msiexecPath -ArgumentList /x, `"$ExcelAddinInstaller`", TARGETDIR=$ExcelAddinTargetDir, /quiet, /lvx, "D:\Temp\uninstall.log" -Wait $proc = Start-Process $msiexecPath -ArgumentList /i, `"$ExcelAddinInstaller`", TARGETDIR=$ExcelAddinTargetDir, /quiet, /lvx, "D:\Temp\install.log" -Wait -ErrorAction Stop echo "Installing addin" Start-Process "C:\Windows\Microsoft.NET\Framework64\v4.0.30319\RegAsm.exe" -ArgumentList /tlb, "C:\Users\Serviceadmin\Addin\MyAddin\Release\MyAddin.dll" } else{ echo $ExcelAddinInstaller } } 

PS:我正在添加.dll文件,因为我的macros中的助手函数调用了我的C#代码。

但是,打开这些xlsm文件时,出现以下错误:

使用“1”参数调用“打开”的exception:“Microsoft Excel无法访问文件'D:\ ABC \ XYZ \ workspace \ library.xlsm'有几种可能的原因:文件名或path不存在。该文件正在被另一个程序使用。您尝试保存的工作簿与当前打开的工作簿具有相同的名称。 在C:\ Users \ Serviceadmin \ AppData \ Local \ Temp \ hudson.ps1:94 char:3 + $ libraryBook = $ excel.workbooks.open(“$ xlLibraryPath \ $ xlLibraryFileName”); +〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜 ~~~~~~~~~~~~~~~~~~~~~~~~types信息:未指定:(:) [],MethodInvocationException + FullyQualifiedErrorId:ComMethodTargetInvocation

尽pipe文件的path是正确的,上面的错误出现了。 这是我如何使用PowerShell打开我的文件:

 $excel = new-object -comobject excel.application; $excel.visible = $true; $libraryBook = $excel.workbooks.open("$xlLibraryPath\$xlLibraryFileName"); $testWorkbook = $excel.workbooks.open("$testFile") $excel.Run("$xlLibraryFileName!Initialize", "$testAct") $loginsuccess = $excel.Run("$xlLibraryFileName!Login", "$xlenvironment", "$xlUserName", "$xlPassword"); if($loginsuccess) { $excel.Run("PerformTest"); $excel.Run("$xlLibraryFileName!Logout"); } $testWorkbook.close($false) $libraryBook.close($false) $excel.quit() 

我已经validation了以下内容:
1. Excel是安装在所需的机器 – 是,Excel 2013
2. xlsm文件的path – 全部存在
3.成功安装插件

有什么我失踪了吗?

提前致谢! 🙂

那么,事实certificate,我不得不在以下每个path添加文件夹 – “桌面”。 解决scheme很奇怪,但现在正在为我工​​作:

C:\ Windows \ System32 \ config \ systemprofile \ Desktop(对于32位机器应该存在,甚至对于64位)

C:\ Windows \ SysWOW64 \ config \ systemprofile \ Desktop(仅适用于64位机器)