Moderatori: Anthony47, Flash30005
tablId = Array(1, 2, 4, 5) '<<Completare
tablSh = Array("SNAI", "BetClick", "MatchPoint", "TotoSi") '<<< Completare
La macro iniziale e' fatta apposta per importare una specifica tabella (la 5°); se tu importi tutte le tabelle allora utilizzi un'altra delle macro pubblicate nella discussione.ho usato la macro iniziale per importare le tabelle da una pagina web e fin lì tutto ok
Sub GetWebTab2()
Dim IE As Object, F As Long
Dim myRColl, myDColl, KK As Long, I As Long, J As Long, myColl, myR, myTD
'
myURL = "https://www.diretta.it/partita/KM0uLUiT/#informazioni-partita" '<<<<
Set IE = CreateObject("InternetExplorer.Application")
'
With IE
.navigate myURL
.Visible = False
Do While .Busy: DoEvents: Loop 'Attesa not busy
Do While .readyState <> 4: DoEvents: Loop 'Attesa documento
End With
'
myStart = Timer 'attesa addizionale
Do
DoEvents
If Timer > myStart + 2 Or Timer < myStart Then Exit Do
Loop
'Leggi le tabelle su foglio5 (su un nuovo foglio)
'Worksheets.Add '<<<<<1 -Nuovo foglio
Application.Goto (Sheets("Foglio2").Range("A1")) '<<<<<2 -Foglio esistente
Cells.Clear
Set myColl = IE.Document.getElementsbyTagName("TABLE")
For Each myItm In myColl
Cells(I + 1, "A").Value = "TABELLA_" & KK: KK = KK + 1: I = I + 1
For Each trtr In myItm.Rows
For Each tdtd In trtr.Cells
Cells(I + 1, J + 1) = tdtd.innertext
J = J + 1
Next tdtd
I = I + 1: J = 0
Next trtr
I = I + 2
Next myItm
'Legge le tabelle dentro gli iframe:
Set myColl = IE.Document.getElementsbyTagName("iframe")
For F = 0 To myColl.Length - 1
If Left(myColl(F).ID, 7) = "myframe" Then
Set my2coll = myColl(F).contentDocument.getElementsbyTagName("table")
For Each myItm In my2coll
Cells(I + 1, "A").Value = "TABELLA_" & KK: KK = KK + 1: I = I + 1
Set myRColl = myItm.getElementsbyTagName("tr")
For Each myR In myRColl
Set myDColl = myR.getElementsbyTagName("td")
For Each myTD In myDColl
Cells(I + 1, J + 1) = myTD.innertext
J = J + 1
Next myTD
I = I + 1: J = 0
Next myR
I = I + 2
Next myItm
End If
Next F
'
Cells.WrapText = False
Range("A1").Select
'
'Stop 'Vedi testo
'
'Chiusura IE
IE.Quit
Set IE = Nothing
End Sub
Sub prendiTab()
zzz = GetTabRaim222("https://www.diretta.it/partita/KM0uLUiT/#informazioni-partita", 4, Sheets("Foglio4").Range("G4"))
If zzz <> 1 Then
MsgBox ("Operazione non riuscita")
Else
MsgBox ("Tabella importata")
End If
End Sub
Sub GetWebTab2AA()
Dim IE As Object, F As Long
Dim myRColl, myDColl, KK As Long, I As Long, J As Long, myColl, myR, myTD
'
myUrl = "https://www.diretta.it/squadra/los-angeles-lakers/ngegZ8bg/" '<<<<
Set IE = CreateObject("InternetExplorer.Application")
'
With IE
.navigate myUrl
.Visible = True 'False
Do While .Busy: DoEvents: Loop 'Attesa not busy
Do While .readyState <> 4: DoEvents: Loop 'Attesa documento
End With
'
myStart = Timer 'attesa addizionale
Do
DoEvents
If Timer > myStart + 2 Or Timer < myStart Then Exit Do
Loop
Sheets("Foglio4").Range("A:Z").ClearContents
Set myColl = IE.document.getElementById("fs-summary-results")
With myColl.getElementsByTagName("Table")(0)
Set myRColl = .getElementsByTagName("TR")
For Each myItm In myRColl
mysplit = Split(myItm.ID, "_", , vbTextCompare)
If UBound(mysplit) > 0 Then
mytar = "https://www.diretta.it/partita/" & mysplit(UBound(mysplit)) & "/#informazioni-partita"
zzz = GetTabRaim222(mytar, 4, Sheets("Foglio4").Cells(Rows.Count, 1).End(xlUp).Offset(5, 0))
If zzz <> 1 Then Stop
End If
Next myItm
End With
IE.Quit
Set IE = Nothing
MsgBox ("Completato...")
End Sub
Function GetTabRaim222(ByVal uurrll As String, ByVal ttAAbb As Long, myDest As Range) As Variant
Dim BetFlag As Boolean, myColl, my2Coll, IE As Object, LnkCnt As Long
Dim myRetr As Long, I0 As Long, I As Long, myLink As Object
'
myUrl = urll '"https://www.diretta.it/squadra/orlando-magic/QZMS36Dn/"
Set IE = CreateObject("InternetExplorer.Application")
'
Refr:
With IE
'Debug.Print "---------"
.navigate myUrl
.Visible = False
End With
'wait for page...
myreS = ieWaitPage(IE, 1, 60) 'sessione, Stab Time, TimeOut time
If myreS <> 0 Then
If myRetr < 5 Then
myRetr = myRetr + 1
GoTo Refr
Else
Rispo = MsgBox("3 errori sulla pagina; recuperare manualmente e poi:" _
& vbCrLf & "-premere OK se recuperato" _
& vbCrLf & "-premere CANCEL se non recuperabile e quindi Abort della raccolta", vbOKCancel)
If Rispo <> vbOK Then GoTo AbortA
End If
End If
myRetr = 0
'
'Leggi le tabelle
myDest.Cells(1, 1).Resize(100, 20).ClearContents
'Stop
DoEvents
''I = 5
Set myColl = IE.document.getElementsByTagName("TABLE")
''Set my2Coll = IE.document.getElementsByTagName("A")
If myColl.Length >= ttAAbb Then 'Vedi "Edit" in fondo
Set myItm = myColl(ttAAbb - 1)
Else
GoTo AbortA
End If
For Each trtr In myItm.Rows
For Each tdtd In trtr.Cells
myDest.Cells(1, 1).Offset(KK, jj) = tdtd.innertext
jj = jj + 1
Next tdtd
KK = KK + 1: jj = 0
Next trtr
GetTabRaim222 = 1 '1=Ok
'
''Stop 'Vedi testo
'
fineA:
'Chiusura IE
IE.Quit
Set IE = Nothing
Set myColl = Nothing
Exit Function
'
AbortA:
GetTabRaim222 = 0 '0=Abort
GoTo fineA
End Function
Sub myWait(ByVal myStab As Single)
Dim myStTim As Single
'
myStTim = Timer
Do 'wait myStab
DoEvents
If Timer > myStTim + myStab Or Timer < myStTim Then Exit Do
Loop
End Sub
Function ieWaitPage(ByRef iEs As Object, ByVal myStab As Long, ByVal myTO As Long) As Long
'0=ok; 1=timeout su .Busy; 2=timeout su .ReadyState; 4=Altro errore
'
Dim myStTim As Single, FlErr As Long
'
On Error GoTo FatErr
myStTim = Timer
Call myWait(0.2) 'wait iniziale
'
With iEs
Do While .Busy: DoEvents:
If Timer > myStTim + myTO Or Timer < myTO Then FlErr = 1: Exit Do
Loop 'Attesa not busy
Do While .readyState <> 4: DoEvents
If FlErr <> 0 Then Exit Do
If Timer > myStTim + myTO Or Timer < myTO Then FlErr = FlErr + 2: Exit Do
Loop 'Attesa documento
End With
If FlErr = 0 Then
aazzz = myStab
Call myWait(myStab)
End If
ieWaitPage = FlErr
Exit Function
FatErr:
ieWaitPage = FlErr + 4
End Function
Sub GetWebTab2AA()
Dim IE As Object, F As Long
Dim myRColl, myDColl, KK As Long, I As Long, J As Long, myColl, myR, myTD
'
myUrl = "https://www.diretta.it/squadra/orlando-magic/QZMS36Dn/" '<<<<
Set IE = CreateObject("InternetExplorer.Application")
'
With IE
.navigate myUrl
.Visible = False
Do While .Busy: DoEvents: Loop 'Attesa not busy
Do While .readyState <> 4: DoEvents: Loop 'Attesa documento
End With
'
myStart = Timer 'attesa addizionale
Do
DoEvents
If Timer > myStart + 2 Or Timer < myStart Then Exit Do
Loop
Sheets("Foglio4").Range("A:Z").ClearContents
Set myColl = IE.document.getElementById("fs-summary-results")
With myColl.getElementsByTagName("Table")(0)
Set myRColl = .getElementsByTagName("TR")
For Each myItm In myRColl
mysplit = Split(myItm.ID, "_", , vbTextCompare)
If UBound(mysplit) > 0 Then
mytar = "https://www.diretta.it/partita/" & mysplit(UBound(mysplit)) & "/#informazioni-partita"
zzz = GetTabRaim222(mytar, 4, Sheets("Foglio4").Cells(Rows.Count, 1).End(xlUp).Offset(5, 0))
If zzz <> 1 Then Stop
End If
Next myItm
End With
IE.Quit
Set IE = Nothing
MsgBox ("Aggiornamento completato")
End Sub
If zZz <> 1 Then
Debug.Print "NOK: ", zZz, mytar
Debug.Print 2, myurl
Debug.Print 3, Sheets("Foglio4").Cells(Rows.Count, 1).End(xlUp).Offset(5, 0).Row
Else
Debug.Print "OK", zZz, mytar
Debug.Print 11, Sheets("Foglio4").Cells(Rows.Count, 1).End(xlUp).Offset(5, 0).Row
End If
Set myColl = IE.document.getElementById("fs-results")
If zZz <> 1 Then
Debug.Print "NOK: ", zZz, mytar
Debug.Print 2, myurl
Debug.Print 3, Sheets("Foglio4").Cells(Rows.Count, 1).End(xlUp).Offset(5, 0).Row
Else
Debug.Print "OK", zZz, mytar
Debug.Print 11, Sheets("Foglio4").Cells(Rows.Count, 1).End(xlUp).Offset(5, 0).Row
End If
Call myWait(0.5) 'wait iniziale
Function GetTabRaim222Denis7(ByVal uurrll As String, ByVal ttAAbb As String, myDest As Range) As Variant
'Vedi http://www.pc-facile.com/forum/viewtopic.php?f=26&t=100441&p=642086#p642086
'Variante della Function GetTabRaim222
'Usa Classname per identificare la tabella da importare
'
'restituisce: N°TabellaImportata + TotTabellePresenti/100, se esito regolare
' 0, se esito irregolare
Dim BetFlag As Boolean, myColl, my2Coll, IE As Object, LnkCnt As Long
Dim myRetr As Long, I0 As Long, I As Long, myLink As Object
'
myurl = uurrll '
Set IE = CreateObject("InternetExplorer.Application")
'
Refr:
With IE
'Debug.Print "---------"
.navigate myurl
.Visible = True
End With
'wait for page...
myreS = ieWaitPage(IE, 1, 60) 'sessione, Stab Time, TimeOut time
If myreS <> 0 Then
If myRetr < 5 Then
myRetr = myRetr + 1
GoTo Refr
Else
Rispo = MsgBox("3 errori sulla pagina; recuperare manualmente e poi:" _
& vbCrLf & "-premere OK se recuperato" _
& vbCrLf & "-premere CANCEL se non recuperabile e quindi Abort della raccolta", vbOKCancel)
If Rispo <> vbOK Then GoTo AbortA
End If
End If
myRetr = 0
'
'Leggi le tabelle
myDest.Cells(1, 1).Resize(500, 20).ClearContents
'Stop
DoEvents
''I = 5
Set myColl = IE.document.getElementsByTagName("TABLE")
''Set my2Coll = IE.document.getElementsByTagName("A")
If myColl.Length = 0 Then 'Vedi "Edit" in fondo
GoTo AbortA
End If
' Set myItm = myColl(ttAAbb - 1)
For Each myItm In myColl
I = I + 1
If myItm.className = ttAAbb Then
For Each trtr In myItm.Rows
For Each tdtd In trtr.Cells
myDest.Cells(1, 1).Offset(KK, jj) = tdtd.innerText
jj = jj + 1
Next tdtd
KK = KK + 1: jj = 0
Next trtr
Exit For
End If
Next myItm
GetTabRaim222Denis7 = I + myColl.Length / 100 '>1=Ok
'
'Stop 'Vedi testo
'
fineA:
'Chiusura IE
IE.Quit
Set IE = Nothing
Set myColl = Nothing
Exit Function
'
AbortA:
GetTabRaim222Denis7 = 0 '0=Abort
GoTo fineA
End Function
Sub GetWebTab2AAB()
'prove dep Denis7
Dim IE As Object, F As Long
Dim myRColl, myDColl, KK As Long, I As Long, J As Long, myColl, myR, myTD
'
myurl = "https://www.diretta.it/squadra/los-angeles-lakers/ngegZ8bg/" '<<<<
Set IE = CreateObject("InternetExplorer.Application")
'
With IE
.navigate myurl
.Visible = True 'False
Do While .busy: DoEvents: Loop 'Attesa not busy
Do While .readystate <> 4: DoEvents: Loop 'Attesa documento
End With
'
myStart = Timer 'attesa addizionale
Do
DoEvents
If Timer > myStart + 2 Or Timer < myStart Then Exit Do
Loop
Sheets("Foglio4").Range("A:I").ClearContents
Set myColl = IE.document.getElementById("fs-summary-results")
With myColl.getElementsByTagName("Table")(0)
Set myRColl = .getElementsByTagName("TR")
For Each myItm In myRColl
mysplit = Split(myItm.ID, "_", , vbTextCompare)
If UBound(mysplit) > 0 Then
mytar = "https://www.diretta.it/partita/" & mysplit(UBound(mysplit)) & "/#informazioni-partita"
' zZz = GetTabRaim222(mytar, 4, Sheets("Foglio4").Cells(Rows.Count, 1).End(xlUp).Offset(5, 0))
zZz = GetTabRaim222Denis7(mytar, "parts-first horizontal", Sheets("Foglio4").Cells(Rows.Count, 1).End(xlUp).Offset(5, 0))
If zZz < 1 Then
Debug.Print "NOK: ", zZz, mytar
Debug.Print 2, myurl
Debug.Print 3, Sheets("Foglio4").Cells(Rows.Count, 1).End(xlUp).Offset(5, 0).Row
Else
Debug.Print "OK", zZz, mytar
Debug.Print 11, Sheets("Foglio4").Cells(Rows.Count, 1).End(xlUp).Offset(5, 0).Row
End If
End If
Next myItm
End With
IE.Quit
Set IE = Nothing
End Sub
Torna a Applicazioni Office Windows
Visitano il forum: raimea e 37 ospiti