使用WScript.Shell.Run的Excel VBA错误 [英] Excel VBA error using WScript.Shell.Run

查看:161
本文介绍了使用WScript.Shell.Run的Excel VBA错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近从Excel 2010升级到Excel 2013后,我将一个自定义加载项(.xlam)移动到新的Application.LibraryPath目录(C:\Program Files\Microsoft Office 15\root\office15\\ \\Library\BTRTools)。有一些代码启动可执行文件(exe)(位于加载项的子目录中)。但是,由于升级/移动,我没有得到错误:



PrettyPrintXml.exe - 应用程序错误 / p>

应用程序无法正确启动(0xc000007b)。点击确定关闭应用程序。



我很明白这是文件权限。我已经将自己的权限显式添加到\Library文件夹(和所有子文件夹)的完整权限。请注意,我认为即使使用Excel 2010(C:\Program Files(x86)\ Microsoft Office\Office14\Library中的文件夹)也可以执行此操作,以使事情正常工作。



但是,毕竟,我仍然坚持不能启动exe文件。任何关于如何使这项工作的想法/建议?



代码是非常标准的:

 code> Public Sub RunShellExecute(sFile As String,可选参数As String =,可选wait As Boolean = False)

Dim wsh As Object:设置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)

如果errorCode = 0然后
'// MsgBoxDone!没有错误报告。
Else
MsgBox程序退出,错误代码& errorCode&
End If

End Sub


解决方案

我知道你的问题是为什么这不工作,但是我以为你可能对替代解决方案感兴趣:有一个本地VBA PrettyPrintXML 。您需要通过单击工具--->引用...添加对VBA项目中MSXML库的引用,然后选中 Microsoft XML,v6.0 (或您的Office / Windows版本附带的任何版本)。


After recently upgrading from Excel 2010 to Excel 2013, I moved a custom add-in (.xlam) to the new Application.LibraryPath directory (C:\Program Files\Microsoft Office 15\root\office15\Library\BTRTools). There is a bit of code that launches an executable (exe) file (located in sub directory of the add-in). However, since the upgrade/move, I am not getting an error:

PrettyPrintXml.exe - Application Error

The application was unable to start correctly (0xc000007b). Click OK to close the application.

I'm obviously pretty convinced it is file permissions. I have explicitly added myself permissions with full rights to the \Library folder (and all subs). Note that I think I had to do this even with Excel 2010 (folder at C:\Program Files (x86)\Microsoft Office\Office14\Library) to make things work.

However, after all this, I'm still stuck and can not launch the exe file. Any ideas/suggestions on how to make this work?

Code is pretty standard:

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

解决方案

I know your question is "Why doesn't this work", but I thought you might be interested in an alternate solution: There is a native VBA PrettyPrintXML. You need to add a reference to the MSXML library in your VBA project by clicking "Tools" ---> "References..." and then check the box next to Microsoft XML, v6.0 (or whatever version is included with your version of Office/Windows).

这篇关于使用WScript.Shell.Run的Excel VBA错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆