Re : Syntaxe de commande SHELL
Bonsour®
on peut utiliser l'alternative suivante :
Code VBA:
Const SW_SHOW = 1
Const SW_SHOWMAXIMIZED = 3
Const SE_ERR_FNF = 2&
Const SE_ERR_PNF = 3&
Const SE_ERR_ACCESSDENIED = 5&
Const SE_ERR_OOM = 8&
Const SE_ERR_DLLNOTFOUND = 32&
Const SE_ERR_SHARE = 26&
Const SE_ERR_ASSOCINCOMPLETE = 27&
Const SE_ERR_DDETIMEOUT = 28&
Const SE_ERR_DDEFAIL = 29&
Const SE_ERR_DDEBUSY = 30&
Const SE_ERR_NOASSOC = 31&
Const ERROR_BAD_FORMAT = 11&
Public Declare Function ShellExecute Lib "Shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, _
ByVal lpOperation As String, _
ByVal lpFile As String, _
ByVal lpParameters As String, _
ByVal lpDirectory As String, _
ByVal nShowCmd As Long) As Long
Sub RunYourProgram()
Dim RetVal As Long
On Error Resume Next
RetVal = ShellExecute(0, "open", "chemin complet de l'élément à ouvrir", Vbnullstring, "C:\", SW_SHOWMAXIMIZED)
End Sub
- permet d'ouvrir n'importe quel fichier dont l'extension est connue de Windows.
- Windows utilise alors le programme par defaut associé pour ouvrir le fichier.
le code retour RETVAL permet de connaitre l'anomalie éventuelle :
If the function fails, the return value is an error value that is less than or equal to 32. The following table lists these error values:
0
The operating system is out of memory or resources.
ERROR_FILE_NOT_FOUND
The specified file was not found.
ERROR_PATH_NOT_FOUND
The specified path was not found.
ERROR_BAD_FORMAT
The .EXE file is invalid (non-Win32 .EXE or error in .EXE image).
SE_ERR_ACCESSDENIED
The operating system denied access to the specified file.
SE_ERR_ASSOCINCOMPLETE
The filename association is incomplete or invalid.
SE_ERR_DDEBUSY
The DDE transaction could not be completed because other DDE transactions were being processed.
SE_ERR_DDEFAIL
The DDE transaction failed.
SE_ERR_DDETIMEOUT
The DDE transaction could not be completed because the request timed out.
SE_ERR_DLLNOTFOUND
The specified dynamic-link library was not found.
SE_ERR_FNF
The specified file was not found.
SE_ERR_NOASSOC
There is no application associated with the given filename extension.
SE_ERR_OOM
There was not enough memory to complete the operation.
SE_ERR_PNF
The specified path was not found.
SE_ERR_SHARE
A sharing violation occurred.