When I run the next Code it triggers an alert that says Error '70', but when I run it Step by Step It works Perfectly !!!!
Sub Arribos ()
Dim IE As Object
Dim objElement As Object
Dim objCollection As Object
Dim i As Integer
Dim j As Double
Dim K As Double
Dim S As Double
Dim l As Object
Dim Cols As Integer
Dim SPAN_ULTIMO_NUM As Integer
Application.Calculation = xlCalculationAutomatic
' OPTIMIZO
Application.ScreenUpdating = False
' BORRO HOJA TAMS ARRIBOS
Cols = Hoja9.Range("R1").Value
If Cols <> 1 Then
For i = 2 To Cols
Hoja9.Rows(2).Delete Shift:=xlUp
Next
End If
Cols = Hoja12.Range("R1").Value
If Cols <> 1 Then
For i = 2 To Cols
Hoja12.Rows(2).Delete Shift:=xlUp
Next
End If
' ABRO EXPLORER Y COMIENZO
Set IE = CreateObject("InternetExplorer.Application") ' Crea el objeto (abre IE)
IE.Visible = True ' Si pones False, no abre la ventana
IE.Navigate "http://www.tams.com.ar/organismos/" ' URL de TAMS
Do While IE.Busy ' Espera mientras esta cargando
Application.Wait DateAdd("s", 1, Now)
Loop
Set objCollection = IE.Document.GetElementsByTagName("select") ' Encuentra todos los <select>
Do While IE.Busy
Application.Wait DateAdd("s", 1, Now)
Loop
OCLength = objCollection.Length
i = 0
While i < OCLength ' Mientras haya inputs...
If objCollection(i).Name = "ddlMovTp" Then ' Arribos
objCollection(i).Value = "A"
Else
If objCollection(i).Name = "ddlAeropuerto" Then ' Aeropuerto EZE
objCollection(i).Value = "EZE"
Else
If objCollection(i).Name = "ddlVentanaH" Then ' Ventana Horaria -48hs
objCollection(i).Value = "-24"
objCollection(i).FireEvent ("onchange")
End If
End If
End If
i = i + 1
Wend
Do While IE.Busy
Application.Wait DateAdd("s", 1, Now)
Loop
K = 2
SPAN_ULTIMO = Right(IE.Document.querySelector("tr.Pager td").textContent, 1)
If SPAN_ULTIMO <> "." Then
SPAN_ULTIMO = CInt(SPAN_ULTIMO)
End If
SPAN_SELECCIONADO = CInt(IE.Document.querySelector("tr.Pager td span").textContent)
While SPAN_ULTIMO <> SPAN_SELECCIONADO
' Cuando es un número me lo toma, cuando no es no!
SPAN_ULTIMO = Right(IE.Document.querySelector("tr.Pager td").textContent, 1)
If SPAN_ULTIMO <> "." Then
SPAN_ULTIMO = CInt(SPAN_ULTIMO)
End If
SPAN_SELECCIONADO = CInt(IE.Document.querySelector("tr.Pager td span").textContent)
i = 0
Do While IE.Busy
Application.Wait DateAdd("s", 1, Now)
Loop
Set objCollection = IE.Document.getelementsbyclassname("tdBlanco")(0).GetElementsByTagName("td") ' Encuentra la tabla de Tams
S = objCollection.Length
While i < S ' Mientras haya <tr> ...
j = 1
While j < 17 And i < S
Do While IE.Busy
Application.Wait DateAdd("s", 1, Now)
Loop
**Hoja9.Cells(K, j).Value = objCollection(i).textContent**
Do While IE.Busy
Application.Wait DateAdd("s", 1, Now)
Loop
j = j + 1
i = i + 1
Wend
K = K + 1
Wend
K = K - 1
' Paso de Ventana
If SPAN_ULTIMO <> SPAN_SELECCIONADO Then
IE.Document.querySelector("tr.Pager td span").NextSibling.NextSibling.Click
End If
' Espera mientras esta cargando
While IE.Busy
Application.Wait DateAdd("s", 1, Now)
Wend
Wend
Cols = Hoja9.Range("R1").Value
If Cols <> 1 Then
For i = 2 To Cols
If Hoja9.Cells(i, 1) = "Cía." Then
Rows(i & ":" & i).Delete Shift:=xlUp
End If
Next
Cols = Hoja9.Range("R1").Value
Hoja9.Rows(Cols & ":" & Cols).Delete Shift:=xlUp
End If
IE.Quit
End Sub
The mistakes is in this part of the code:
**Hoja9.Cells(K, j).Value = objCollection(i).textContent**
Line 115.
Thanks a lot !!!