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 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
|
Option Explicit
Dim t!
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Private Declare Function SWL Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Private Declare Function BringWindowToTop Lib "user32" (ByVal hwnd As Long) As Long
Declare Sub mouse_event Lib "user32" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)
Private Declare Function SetCursorPos Lib "user32" (ByVal X As Long, ByVal Y As Long) As Long
Public Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal X As Long, ByVal Y As Long) As Long
Public Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
Public IE As Object
Dim TTVE As Long
Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Sub Demo2()
Const ELT = "ctl00_BodyABC_Button1"
Dim Wb As Workbook, r As RECT, HIEFRAME As Long, i As Long, hwndIEedge As Long, X As Long, Y As Long, couleur As Long, c As Boolean
t = Timer
For Each Wb In Workbooks
If Wb.Name Like "Cotations*.csv" Then Wb.Close False
Next
Set IE = CreateObject("InternetExplorer.Application")
With IE
.Navigate "http://www.abcbourse.com/download/historiques.aspx"
'.Visible = True 'facultatif!!!!!!!
While .ReadyState < 3
If Timer - t > 9 Then GoTo Fin
Wend
While Not IsObject(.Document.all(ELT))
If Timer - t > 9 Then GoTo Fin
Wend
On Error GoTo Fin
With .Document.all
.ctl00_BodyABC_strDateDeb.Value = "26/05/2015"
.ctl00_BodyABC_strDateFin.Value = "26/05/2016"
.ctl00_BodyABC_oneSico.Click
.ctl00_BodyABC_txtOneSico.Value = "FR0000120222"
.ctl00_BodyABC_dlFormat.Value = "x"
.Item(ELT).Click
End With
On Error GoTo 0
.Visible = True
HIEFRAME = IE.hwnd 'FindWindow("IEFrame", vbNullString)
.Visible = True
BringWindowToTop IE.hwnd
Sleep 500
Do
DoEvents: i = i + 1
hwndIEedge = FindWindowEx(HIEFRAME, 0&, "Frame Notification Bar", vbNullString) 'recherche du handle de la fenetre de telechargement IE edge
Loop While hwndIEedge = 0 Or i = 20000
GetWindowRect hwndIEedge, r
' BringWindowToTop HieFrame
Do
BringWindowToTop HIEFRAME
DoEvents: i = i + 1
X = r.Right - (4 * i): Y = r.Bottom - (2 * i)
SetCursorPos X, Y ' on fait bouger le curseur dans le bandeau ca permet que son fond reste blanc
couleur = GetPixel(GetDC(0), X, Y) 'on capte la couleur du point X/Y
If couleur = 16777215 Then c = True
Loop Until c = True And couleur <> 16777215 Or i > 50 'jusqu'a que la couleur soit differente de blanc ou a 10 de la fin du bandeau
i = 0
Do
DoEvents
i = i + 50
X = r.Left + i:
SetCursorPos X, Y - 4 ' on fait bouger le curseur dans le bandeau ca permet que son fond reste blanc
couleur = GetPixel(GetDC(0), X, Y) 'on capte la couleur du point X/Y
Debug.Print couleur
'Sleep 200
Loop Until (couleur <> 16777215) Or X > r.Right 'jusqu'a que la couleur soit differente de blanc ou a la fin du bandeau
SetCursorPos X + 10, Y ' on ajoute 10 a X pour etre bien dans le bouton
mouse_event &H2, 0, 0, 0, 0
mouse_event &H4, 0, 0, 0, 0
' le fond de la fenetre est blanc =16777215
'la couleur du bouton over=16576741
TTVE = 0
Application.OnTime Now + TimeValue("00:00:01"), "fermeIE"
Fin:
If X > r.Right Then Beep: MsgBox "beep beep n'a pas trouvé le bouton " & vbCrLf & "vous pouvez néammoins cliquer dessus manuellement "
BringWindowToTop hwndIEedge
End With
End Sub
Private Sub fermeIE()
If TTVE < 4 Then
If ActiveWorkbook.Name <> ThisWorkbook.Name Then
IE.Quit: TTVE = TTVE + 1
Else
Application.OnTime Now + TimeValue("00:00:01"), "fermeIE"
End If
Else
MsgBox "le telechargement n'a pas éte effectué"
End If
End Sub |
Partager