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 75
| Private 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
Private Declare Function GetDesktopWindow Lib "user32" () As Long
Private Const SW_SHOWNORMAL As Long = 1
Sub tt()
num1 = [g1] '1129
num2 = [g2] '1001
nom = num1 & "." & num2
chemin = "C:\temp\pdf\"
' Renvoie le nom de fichier avec l'extension indiquée. Si plusieurs
' fichiers *.PDF existent, le premier fichier trouvé est renvoyé.
NomDuFichier = Dir(chemin & nom & "*.PDF")
While NomDuFichier <> ""
Call OuvrirAvecApplicationAssocie(chemin & NomDuFichier)
' Appelle de nouveau Dir sans argument pour renvoyer le
' fichier *.PDF suivant dans le même dossier.
NomDuFichier = Dir
Wend
End Sub
Public Function RunShellExecute(sTopic As String, _
sFile As Variant, _
sParams As Variant, _
sDirectory As Variant, _
nShowCmd As Long) As Long
Dim hWndDesk As Long
Dim success As Long
'the desktop will be the
'default for error messages
hWndDesk = GetDesktopWindow()
'execute the passed operation
success = ShellExecute(hWndDesk, sTopic, sFile, sParams, sDirectory, nShowCmd)
End Function
Sub OuvrirAvecApplicationAssocie(sFile)
Dim sTopic As String
sTopic = "Open"
sParams = 0&
sDirectory = 0&
Call RunShellExecute(sTopic, sFile, sParams, sDirectory, SW_SHOWNORMAL)
End Sub |
Partager