1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
| Private Declare Function ShellExec 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
Public Enum TypeOpen
Hide = 0
Normal = 1
Minimized = 2
Maximized = 3
Restore = 9
End Enum
Public Enum OP
OpExecute = 1
OpPrint = 2
End Enum
Private Const ERROR_SUCCESS = 32&
Private Const ERROR_NO_ASSOC = 31&
Private Const ERROR_OUT_OF_MEM = 0&
Private Const ERROR_FILE_NOT_FOUND = 2&
Private Const ERROR_PATH_NOT_FOUND = 3&
Private Const ERROR_BAD_FORMAT = 11&
Function OuvrirFichier(FileName As String, _
Optional Window As TypeOpen = Maximized _
, Optional Operation As OP = OpExecute _
) As Variant
Dim lRet As Long
Dim varTaskID As Variant
Dim stRet As String
If Dir(FileName, vbHidden) = "" Then 'Recherche si le fichier existe _
(vbHidden permet de le retrouver même s'il est caché)
MsgBox "Le fichier " & FileName & " n'existe pas.", vbOKOnly + vbInformation, "Information"
Exit Function
End If
lRet = ShellExec(hWndAccessApp, _
IIf(Operation = OpPrint, "print", "open"), _
FileName, vbNullString, vbNullString, _
Window)
If lRet > ERROR_SUCCESS Then
stRet = vbNullString
lRet = -1
Else
Select Case lRet
Case ERROR_NO_ASSOC:
varTaskID = Shell("rundll32.exe shell32.dll,OpenAs_RunDLL " _
& FileName, 1)
lRet = (varTaskID <> 0)
Case ERROR_OUT_OF_MEM:
stRet = "Erreur: Pas assez de mémoire pour exécuter"
Case ERROR_FILE_NOT_FOUND:
stRet = "Erreur : Fichier non trouvé"
Case ERROR_PATH_NOT_FOUND:
stRet = "Erreur : Chemin non trouvé"
Case ERROR_BAD_FORMAT:
stRet = "Erreur : Type de fichier inconnu"
Case Else:
End Select
End If
OuvrirFichier = lRet & _
IIf(stRet = "", vbNullString, ", " & stRet)
End Function |
Partager