Bonjour,
 
Je cherche a faire en sorte que chaque fois qu un download demarre via internet explorer cela s enregistre automatiquement, selon un nom que j aurais choisi sur une liste (sur excel), dans un repetoire determine prealablement via un macro excel
 
J ai trouve ce code sur ce site. Il permet que lorsqu un download demarre le bouton "save" soit presse 2 fois. Le probleme est ke je ne sais pas comment faire pour que le nom du fichier enregistrer soit celui qui se trouve dans mon fichier excel, ni comment lui dire d enregister dans un repertoire ke j aurais choisi prealablement.
 
Je ne suis pas programmeur a la base, si klkn pouvait m aider ce serait sympa.
 
Merci bien
 
Le code:
 
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()
 
    Set ie = CreateObject("InternetExplorer.Application" )
   
    acceuil = "google"
             
    '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
     
        ie.Navigate acceuil
        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)
         
        PostMessage hwnd_fils, WM_KEYDOWN, VK_RETURN, 0 'enter
                         
    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