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 110 111
| Sub Macro2()
Clic1 = False
Clic2 = False
Clic3 = False
On Error GoTo ExempleErreur
Sheets("Hypertxt").Select
Dim o As Long
o = 1
Dim DerniereLigne
DerniereLigne = Range("A1").End(xlDown).Row
While o <= DerniereLigne
If Cells(o, 4) = "" Then
If Clic1 = False Then
'Mettez le début de votre procédure ici
DeclencheLien Range("E" & o)
Dim IEdoc As Object
Dim DOCelement As Object
Set ie = CreateObject("InternetExplorer.application")
ie.Visible = False
'attente de fin de chargement
Do Until ie.ReadyState = 4
DoEvents
Loop
Set IEdoc = ie.Document
'login
Set DOCelement = IEdoc.getElementsByName("LoginForm_Login").Item
DOCelement.Value = "****" 'Login
'password
Set DOCelement = IEdoc.getElementsByName("LoginForm_Password").Item
DOCelement.Value = "****" 'mot de passe
'account
Set DOCelement = IEdoc.getElementsByName("LoginForm_RegistrationDomain").Item
DOCelement.Value = "****" 'mot de passe
DOCelement.Select
'connexion
Set DOCelement = IEdoc.Forms(0)
DOCelement.submit
Application.Wait (Now + TimeValue("0:00:03"))
'attente de fin de chargement
Do Until ie.ReadyState = 4
DoEvents
Loop
Cells(o, 4).Value = "Exist"
Set IEdoc = ie.Document
ie.Quit
Clic1 = True
MsgBox ("Clic1 = True")
Worksheets("Button").Activate
Exit Sub
ElseIf Clic2 = False Then
'Mettez le milieu de votre procédure ici
Dim Xx As String
Xx = Worksheets("Hypertxt").Cells(o, 3).Value
FileCopy "C:\Users\stagiaire\Downloads\Commande.xls", "C:\Users\stagiaire\Desktop\Antoine\Test_DL\" & Xx & ".xls"
Kill "C:\Users\stagiaire\Downloads\Commande.xls"
Clic2 = True
MsgBox ("Clic2 = True")
Worksheets("Button").Activate
Exit Sub
Else:
'Mettez la fin de votre procédure ici
MsgBox ("Passer au lien suivant")
Clic1 = False
Clic2 = False
o = o + 1
MsgBox ("Clic1 & 2 = False, Reset")
Worksheets("Button").Activate
End If
End If
Wend
Worksheets("Button").Activate
ExempleErreur:
MsgBox "Les fichiers existent tous"
End Sub
_________________________________________________________________________________________
Sub DeclencheLien(Cellule As Range)
'Vérifie si la cellule contient un lien
If Cellule.HyperLinks.Count = 0 Then
MsgBox "il n'y a pas de lien hypertexte dans la cellule " & Cellule.Address
Else
'Déclenche le lien
Cellule.HyperLinks(1).Follow NewWindow:=True
End If
End Sub |
Partager