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 76 77 78 79 80 81 82
| Option Explicit
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private Declare Function ShowWindow Lib "user32" _
(ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
' Activate an application window.
Private Declare Function SetForegroundWindow Lib "user32.dll" _
(ByVal hwnd As Long) As Boolean
Function GetIE(ByVal titre As String, ByVal action As String, _
Optional ByVal BoucleMax As Long = 20) As String
' getie "Sélect", "WRI=SAPBWHIGH_1=12"
' getie "Sélect. val. filtre", "LNK=javascript:execute_export();"
Dim WinShell As New ShellWindows
Dim IEapp As New InternetExplorer
Dim doc As HTMLDocument
Dim ctl As Object
Dim i As Integer
'On Error Resume Next
For Each IEapp In WinShell
If IEapp.LocationName Like "*" & titre & "*" Then
Select Case Left(action, 3)
Case "WRI" ' remplir un formulaire
Do While IEapp.Busy Or IEapp.ReadyState <> READYSTATE_COMPLETE
DoEvents
Loop 'attend la fin du chargement pour continuer la procedure
Set doc = IEapp.Document
Set ctl = doc.getElementsByName(Split(action, "=")(1))
ctl(0).Value = Split(action, "=")(2)
Case "LNK" ' cas d'un lien
Do While IEapp.Busy Or IEapp.ReadyState <> READYSTATE_COMPLETE
DoEvents
Loop 'attend la fin du chargement pour continuer la procedure
Set doc = IEapp.Document
For i = 0 To BoucleMax
Debug.Print doc.Links(i).href
If doc.Links(i).href = Split(action, "=")(1) Then
doc.Links(i).Click
Exit For
End If
Next i
Do While IEapp.Busy Or IEapp.ReadyState <> READYSTATE_COMPLETE
DoEvents
Loop 'attend la fin du chargement pour continuer la procedure
Case "CLI" ' cas d'un bouton
Do While IEapp.Busy Or IEapp.ReadyState <> READYSTATE_COMPLETE
DoEvents
Loop 'attend la fin du chargement pour continuer la procedure
Set doc = IEapp.Document
Set ctl = doc.getElementsByName(Split(action, "=")(1))
doc.Links(i).Click
Do While IEapp.Busy Or IEapp.ReadyState <> READYSTATE_COMPLETE
DoEvents
Loop 'attend la fin du chargement pour continuer la procedure
Case "CHK" 'vérifier
GetIE = "Ok"
Case "SCR" 'execution de script
Set doc = IEapp.Document
doc.parentWindow.execScript Split(action, "=")(1), "Javascript"
Case "URL" 'retrieve URL
GetIE = IEapp.LocationURL
End Select
Exit Function
End If
Next IEapp
Set doc = Nothing
Set ctl = Nothing
Set IEapp = Nothing
Set WinShell = Nothing
End Function |
Partager