Excel VBA error using WScript.Shell.Run
excel, vba, wsh
Solution
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).
Problem
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 ```