最近从 Excel 2010 升级到 Excel 2013 后,我将自定义加载项 (.xlam) 移动到新的 Application.LibraryPath 目录 (C:\Program Files\Microsoft Office 15\root\office15\Library\BTRTools)。有一些代码可以启动可执行 (exe) 文件(位于加载项的子目录中)。但是,自升级/移动以来,我没有收到错误消息:
PrettyPrintXml.exe - Application Error
The application was unable to start correctly (0xc000007b). Click OK to close the application.
我显然很相信这是文件权限。我已经明确添加了自己对 \Library 文件夹(和所有子文件夹)的完全权限。请注意,我认为即使使用 Excel 2010(位于 C:\Program Files (x86)\Microsoft Office\Office14\Library 的文件夹)也必须这样做才能使事情正常进行。
但是,毕竟这一切,我仍然卡住,无法启动 exe 文件。关于如何完成这项工作的任何想法/建议?
代码非常标准:
Public Sub RunShellExecute(sFile As String, Optional params As String = "", Optional wait As Boolean = False)
Dim wsh As Object: Set wsh = VBA.CreateObject("WScript.Shell")
Dim waitOnReturn As Boolean: waitOnReturn = wait
Dim windowStyle As Integer: windowStyle = 1
Dim exe As String: exe = IIf(Left(sFile, 1) <> """", """" & sFile & """", sFile)
Dim exeParams As String: exeParams = IIf(params <> "", " " & params, "")
Dim errorCode As Integer: errorCode = wsh.Run(exe & exeParams, windowStyle, waitOnReturn)
If errorCode = 0 Then
'// MsgBox "Done! No error to report."
Else
MsgBox "Program exited with error code " & errorCode & "."
End If
End Sub