Discussion:
Fermer un programme externe en VBA ?
(trop ancien pour répondre)
artis31
2004-06-14 01:32:15 UTC
Permalink
Bonjour,

Suite à un post ici où je cherchais à récupérer le contenu d'un fichier pdf
(ce qui marche très bien), je n'arrives pas à fermer l'application Acrobat
Reader à la fin de mon traitement...

Quelqu'un pourrait m'indiquer l'instruction adéquate ?

Voilà comment je l'ai ouvert :

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

Sub Extraire_Texte_de_Pdf()

URL = "C:\mes documents\Gazel_no22.pdf" 'Adapter à votre fichier
'Ouvrir le fichier pdf avec le programme approprié
ShellExecute 0&, vbNullString, URL, vbNullString, _
vbNullString, vbNormalFocus

End Sub
Alain CROS
2004-06-14 12:38:39 UTC
Permalink
Bonjour

Dans un module standard :

Private Declare Function EnumWindows& Lib "user32" _
(ByVal lpEnumFunc&, ByVal lngParam&)

Private Declare Function GetWindowThreadProcessId& Lib "user32" _
(ByVal Hwnd&, lpdwProcessId&)

Private Declare Function SendMessage& Lib "user32" Alias "SendMessageA" _
(ByVal Hwnd&, ByVal wMsg&, ByVal wParam&, lParam As Any)

Private Declare Function GetParent& Lib "user32" _
(ByVal Hwnd&)

Private Declare Function FindExecutable& Lib "shell32" Alias "FindExecutableA" _
(ByVal lpFile$, ByVal lpDirectory$, ByVal lpResult$)

Private Apphwnd&

Sub Ferme_Pdf()
Const WM_SYSCOMMAND& = &H112, SC_CLOSE& = &HF060
SendMessage Apphwnd, WM_SYSCOMMAND, SC_CLOSE, 0&
End Sub

Sub Extraire_Texte_de_Pdf()
Dim URL$
URL = "C:\mes documents\Gazel_no22.pdf" 'Adapter à votre fichier
'Ouvrir le fichier pdf avec le programme approprié
EnumWindows AddressOf EnumWindowsProc, Shell(TrouveEXE(URL) & " """ & URL & """", vbNormalFocus)
End Sub

Private Function TrouveEXE$(LeFile$)
Dim Exe$
Const MAX_PATH& = 260&
Exe = Space$(MAX_PATH)
FindExecutable LeFile, "", Exe
TrouveEXE = Left$(Exe, InStr(Exe, vbNullChar) - 1&)
End Function

Private Function EnumWindowsProc&(ByVal Hwnd&, ByVal lngParam&)
Dim test_pid&
GetWindowThreadProcessId Hwnd, test_pid
If test_pid = lngParam And GetParent(Hwnd) = 0& Then Apphwnd = Hwnd Else EnumWindowsProc = True
End Function

Alain CROS
Post by artis31
Bonjour,
Suite à un post ici où je cherchais à récupérer le contenu d'un fichier pdf
(ce qui marche très bien), je n'arrives pas à fermer l'application Acrobat
Reader à la fin de mon traitement...
Quelqu'un pourrait m'indiquer l'instruction adéquate ?
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
Sub Extraire_Texte_de_Pdf()
URL = "C:\mes documents\Gazel_no22.pdf" 'Adapter à votre fichier
'Ouvrir le fichier pdf avec le programme approprié
ShellExecute 0&, vbNullString, URL, vbNullString, _
vbNullString, vbNormalFocus
End Sub
Loading...