Microsoft 365 [RESOLU] Boucler sur une partie de code

Icedarts

XLDnaute Occasionnel
Bonjour à tous,

J'essaie de faire un code qui prend les valeurs de la colonne A de la feuille 1 du classeur pour les mettre dans une cellule d'une page internet.
Malheureusement je n'arrive pas a boucler sur ce morceau de code pour faire comprendre à la macro de passer de A1 à A2, de A2 à A3 etc etc.

Voici mon code
VB:
Sub testJP()
    Dim IE As Object
    Dim IEdoc As Object
    Dim DOCelement As Object, FrameLeftDoc As Object
    Set IE = CreateObject("InternetExplorer.Application")
    IE.Visible = True
    IE.Navigate ("XXXXXXXXXXXXXXX")
    WaitIE IE
    Set IEdoc = IE.document
    Set FrameLeftDoc = IEdoc.frames("leftframe").document
    Set DOCelement = FrameLeftDoc.all("M21")
    DOCelement.Click
    WaitIE IE
    Set IEdoc = IE.document
    Application.Wait Now() + TimeValue("00:00:01")
    Set FrameLeftDoc = IEdoc.frames("leftframe").document
    'Application.Wait Now() + TimeValue("00:00:5")
    Set DOCelement = FrameLeftDoc.all("A9")
    DOCelement.Click
    WaitIE IE
   
        If Cells(1, 1) Then L = 0
        L = L + 1
        With DOCelement
        Set DOCelement = IEdoc.getElementsByName("A3").Item
        DOCelement.Value = Cells(L, 1).Text
        Set DOCelement = IEdoc.getelementsbytagname("button")(12)
        DOCelement.Click
        End With
 
    If Cells(L + 1, 1) <> "" Then MsgBox ("Traitement terminé !")

    Set IE = Nothing
 
 
End Sub

Et donc la partie sur laquelle j'aimerai boucler c'est
VB:
        If Cells(1, 1) Then L = 0
        L = L + 1
        With DOCelement
        Set DOCelement = IEdoc.getElementsByName("A3").Item
        DOCelement.Value = Cells(L, 1).Text
        Set DOCelement = IEdoc.getelementsbytagname("button")(12)
        DOCelement.Click
        End With
 
    If Cells(L + 1, 1) <> "" Then MsgBox ("Traitement terminé !")

Merci d'avance pour votre aide.
 
Dernière édition:
Solution
Re

Essaye comme ceci

VB:
Sub testJP()
Dim IE As Object
Dim IEdoc As Object
Dim DOCelement As Object, FrameLeftDoc As Object
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True
IE.Navigate ("www.dl-ligue.com")
WaitIE IE
Set IEdoc = IE.document
Set FrameLeftDoc = IEdoc.frames("leftframe").document
Set DOCelement = FrameLeftDoc.all("M21")
DOCelement.Click
WaitIE IE
Set IEdoc = IE.document
Application.Wait Now() + TimeValue("00:00:01")
Set FrameLeftDoc = IEdoc.frames("leftframe").document
'Application.Wait Now() + TimeValue("00:00:5")
Set DOCelement = FrameLeftDoc.all("A9")
DOCelement.Click
WaitIE IE

Dim Derlig&
Derlig = Range("A" & Rows.Count).End(xlUp).Row

For i = 1 To Derlig
    If Cells(i, 1) Then
        With...

Phil69970

XLDnaute Barbatruc
Bonjour @Icedarts

Ma proposition

VB:
    For i = 1 To 24
        If Cells(1, i) Then L = 0
        L = L + 1
        With DOCelement
        Set DOCelement = IEdoc.getElementsByName("A3").Item
        DOCelement.Value = Cells(L, 1).Text
        Set DOCelement = IEdoc.getelementsbytagname("button")(12)
        DOCelement.Click
        End With
    Next i

Par contre il manque le N° de joueur

Merci de ton retour

@Phil69970
 

Icedarts

XLDnaute Occasionnel
Les 24 numéros étaient un exemple, ce nombre sera aléatoire.

ceci ne fonctionnerait pas?
Le numéro du joueur n'est pas nécessaire

VB:
    For L = L + 1
        If Cells(1, L) Then L = 0
         With DOCelement
        Set DOCelement = IEdoc.getElementsByName("A3").Item
        DOCelement.Value = Cells(L, 1).Text
        Set DOCelement = IEdoc.getelementsbytagname("button")(12)
        DOCelement.Click
        End With
    Next L

Après test non ça ne fonctionne pas lol
 
Dernière édition:

Phil69970

XLDnaute Barbatruc
Re

Essaye comme ceci

VB:
Sub testJP()
Dim IE As Object
Dim IEdoc As Object
Dim DOCelement As Object, FrameLeftDoc As Object
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True
IE.Navigate ("www.dl-ligue.com")
WaitIE IE
Set IEdoc = IE.document
Set FrameLeftDoc = IEdoc.frames("leftframe").document
Set DOCelement = FrameLeftDoc.all("M21")
DOCelement.Click
WaitIE IE
Set IEdoc = IE.document
Application.Wait Now() + TimeValue("00:00:01")
Set FrameLeftDoc = IEdoc.frames("leftframe").document
'Application.Wait Now() + TimeValue("00:00:5")
Set DOCelement = FrameLeftDoc.all("A9")
DOCelement.Click
WaitIE IE

Dim Derlig&
Derlig = Range("A" & Rows.Count).End(xlUp).Row

For i = 1 To Derlig
    If Cells(i, 1) Then
        With DOCelement
            Set DOCelement = IEdoc.getElementsByName("A3").Item
            DOCelement.Value = Cells(i, 1).Text
            Set DOCelement = IEdoc.getelementsbytagname("button")(12)
            DOCelement.Click
        End With
    End If
    Application.Wait Now() + TimeValue("00:00:01")'optionnel pour voir les numéros
Next i
 
If Cells(i, 1) <> "" Then MsgBox ("Traitement terminé !")

Set IE = Nothing
End Sub

La boucle se fait bien mais il manque le N° de joueur

Merci de ton retour

@Phil69970
 
Dernière édition:

Discussions similaires

Statistiques des forums

Discussions
312 209
Messages
2 086 263
Membres
103 167
dernier inscrit
miriame