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 103 104 105 106 107 108 109
| Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, ByVal lpWindowName As String) 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 SetActiveWindow Lib "user32.dll" (ByVal hwnd As Long) As Long
Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" _
(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Public hwnd As Long
Private Const WM_KEYDOWN = &H100
Private Const WM_CHAR = &H102
Private Const VK_RETURN = &HD
Private Const BM_CLICK = &HF5
Sub LaunchDownload()
On Error Resume Next
Set ie = CreateObject("InternetExplorer.Application" )
acceuil = "http://intranet"
baseline = "http://intranet/monfichier.csv"
fichier_baseline = "c:\baseline.csv"
If Dir(fichier_baseline) <> "" Then Kill fichier_baseline
'connection à la page d'acceuil intranet pour éviter les problèmes de login/password
ie.Navigate acceuil
'ie.Visible = True
Do Until ie.ReadyState = 4 'Loop unitl ie page is fully loaded
DoEvents
Loop
If ie.document.Title = "Mettre le Header de votre page, c'est juste pour un test" Then
ie.Navigate baseline
Do Until ie.ReadyState = 4
DoEvents
Loop
hwnd = 0
hwnd_fils = 0
Do
hwnd = FindWindow(vbNullString, "File Download" )
If hwnd = 0 Then
PauseTimer (1)
Else
hwnd_button = FindWindowEx(hwnd, 0, "Button", "&Save" )
End If
Loop While hwnd_button = 0
hwnd_button_hexa = Hex(hwnd_button)
hwnd_hexa = Hex(hwnd)
SetActiveWindow hwnd
SendMessage hwnd_button, BM_CLICK, ByVal CLng(0), ByVal CLng(0)
Do
hwnd_fils = FindWindow(vbNullString, "Save As" )
If hwnd_fils = 0 Then
PauseTimer (1)
Else
hwnd_button = FindWindowEx(hwnd_fils, 0, "Button", "&Save" )
hwnd_level1 = FindWindowEx(hwnd_fils, 0, "ComboBoxEx32", "" )
hwnd_level2 = FindWindowEx(hwnd_level1, 0, "ComboBox", "" )
hwnd_level3 = FindWindowEx(hwnd_level2, 0, "Edit", "" )
End If
Loop While hwnd_button = 0
hwnd_fils_hexa = Hex(hwnd_fils)
hwnd_text_hexa = Hex(hwnd_text)
hwnd_level3_hexa = Hex(hwnd_level3)
For num = 1 To Len(fichier_baseline)
PostMessage hwnd_level3, WM_CHAR, Asc(Mid(fichier_baseline, num, 1)), 0
Next
PostMessage hwnd_fils, WM_KEYDOWN, VK_RETURN, 0 'enter
Do
If Dir(fichier) = "" Then
PauseTimer (1)
End If
Loop While Dir(fichier) = ""
Else
MsgBox "Please ensure that you have Internet Explorer opened" & Chr(13) & _
"and that you are already connected to Intranet." & Chr(13) & _
"Note : having multiple IE windows could lead to problems"
End If
ie.Quit
Set ie = Nothing
End Sub
'celle du dessous je l'ai trouvé sur le net... je ne sais plus où, en tout cas merci à celui qui l'a écrite
Sub PauseTimer(ByVal nSecond As Single)
Dim t0 As Single
'temps de référence
t0 = Timer
'boucle d'attente
Do While Timer - t0 < nSecond
Dim dummy As Integer
dummy = DoEvents()
'si on dépasse minuit,il faut
'retrancher un jour
If Timer < t0 Then
t0 = t0 - 24 * 60 * 60
End If
Loop
End Sub |
Partager