Erreur VBA Excel en utilisant WScript.Shell.Run

Après avoir récemment mis à jour depuis Excel 2010 vers Excel 2013, j'ai déplacé un complément personnalisé (.xlam) vers le nouveau directory Application.LibraryPath (C: \ Program Files \ Microsoft Office 15 \ root \ office15 \ Library \ BTRTools). Il y a un peu de code qui lance un file exécutable (exe) (situé dans le sous-directory du complément). Cependant, depuis la mise à niveau / déplacement, je ne reçois pas d'erreur:

PrettyPrintXml.exe - Application Error

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

Je suis évidemment très convaincu que ce sont les permissions de files. J'ai explicitement ajouté mes permissions avec plein droit sur le dossier \ Library (et tous les sous-systèmes). Notez que je pense que je devais le faire même avec Excel 2010 (dossier dans C: \ Program Files (x86) \ Microsoft Office \ Office14 \ Library) pour que les choses fonctionnent.

Cependant, après tout cela, je suis encore coincé et je ne peux pas lancer le file exe. Des idées / suggestions sur la façon de faire fonctionner cela?

Le code est assez standard:

 Public Sub RunShellExecute(sFile As Ssortingng, Optional params As Ssortingng = "", 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 Ssortingng: exe = IIf(Left(sFile, 1) <> """", """" & sFile & """", sFile) Dim exeParams As Ssortingng: 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 Public Sub RunShellExecute (sFile As Ssortingng, Params optionnels As Ssortingng = "", Optional wait As Boolean = False) Public Sub RunShellExecute(sFile As Ssortingng, Optional params As Ssortingng = "", 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 Ssortingng: exe = IIf(Left(sFile, 1) <> """", """" & sFile & """", sFile) Dim exeParams As Ssortingng: 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 Dim wsh As Object: Définir wsh = VBA.CreateObject ("WScript.Shell") Public Sub RunShellExecute(sFile As Ssortingng, Optional params As Ssortingng = "", 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 Ssortingng: exe = IIf(Left(sFile, 1) <> """", """" & sFile & """", sFile) Dim exeParams As Ssortingng: 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 Dim waitOnReturn As Boolean: waitOnReturn = wait Public Sub RunShellExecute(sFile As Ssortingng, Optional params As Ssortingng = "", 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 Ssortingng: exe = IIf(Left(sFile, 1) <> """", """" & sFile & """", sFile) Dim exeParams As Ssortingng: 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 Dim windowStyle As Integer: windowStyle = 1 Public Sub RunShellExecute(sFile As Ssortingng, Optional params As Ssortingng = "", 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 Ssortingng: exe = IIf(Left(sFile, 1) <> """", """" & sFile & """", sFile) Dim exeParams As Ssortingng: 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 Dim exe As Ssortingng: exe = IIf (Left (sFile, 1) <> "" "", "" "" & sFile & "" "", sFile) Public Sub RunShellExecute(sFile As Ssortingng, Optional params As Ssortingng = "", 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 Ssortingng: exe = IIf(Left(sFile, 1) <> """", """" & sFile & """", sFile) Dim exeParams As Ssortingng: 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 Dim exeParams As Ssortingng: exeParams = IIf (params <> "", "" et params, "") Public Sub RunShellExecute(sFile As Ssortingng, Optional params As Ssortingng = "", 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 Ssortingng: exe = IIf(Left(sFile, 1) <> """", """" & sFile & """", sFile) Dim exeParams As Ssortingng: 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 Dim errorCode As Integer: errorCode = wsh.Run (exe & exeParams, windowStyle, waitOnReturn) Public Sub RunShellExecute(sFile As Ssortingng, Optional params As Ssortingng = "", 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 Ssortingng: exe = IIf(Left(sFile, 1) <> """", """" & sFile & """", sFile) Dim exeParams As Ssortingng: 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 Si errorCode = 0 Then Public Sub RunShellExecute(sFile As Ssortingng, Optional params As Ssortingng = "", 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 Ssortingng: exe = IIf(Left(sFile, 1) <> """", """" & sFile & """", sFile) Dim exeParams As Ssortingng: 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 '// MsgBox' Done! Aucune erreur pour signaler. " Public Sub RunShellExecute(sFile As Ssortingng, Optional params As Ssortingng = "", 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 Ssortingng: exe = IIf(Left(sFile, 1) <> """", """" & sFile & """", sFile) Dim exeParams As Ssortingng: 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 MsgBox "Programme sort avec code d'erreur" & errorCode & "." Public Sub RunShellExecute(sFile As Ssortingng, Optional params As Ssortingng = "", 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 Ssortingng: exe = IIf(Left(sFile, 1) <> """", """" & sFile & """", sFile) Dim exeParams As Ssortingng: 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 

Je sais que votre question est "Pourquoi cela ne fonctionne pas", mais je pensais que vous pourriez être intéressé par une solution de rechange: il existe un VBA PrettyPrintXML natif . Vous devez append une reference à la bibliothèque MSXML dans votre projet VBA en cliquant sur "devises" —> "Références …", puis cochez la case à côté de Microsoft XML, v6.0 (ou quelle que soit la version incluse avec votre version d'Office / Windows).

Modifiez le titre de votre question, car Excel VBA est capable d'utiliser WScript.Shell.Run, sinon vous ne recevrez pas votre erreur.

En ce qui concerne le problème réel, cela ressemble à un problème de 32 bits / 64 bits. Vérifiez si le programme que vous appelez est approprié pour votre système et s'il essaie de charger les DLL correctes.

Le problème n'est pas une autorisation de file, alors vous obtiendrez un code d'état différent.

Vous devez utiliser un path sans espaces, quelque chose de simple comme 'C: \ BTRTools'. Ensuite, il devrait fonctionner.