Visual Basic para Aplicaciones - Macro rellena formulario en pagina web (SII contribuciones)

Life is soft - evento anual de software empresarial
 
Vista:

Macro rellena formulario en pagina web (SII contribuciones)

Publicado por Matias Vidal (1 intervención) el 12/10/2018 17:12:54
Estimados junto con saludar , les comento que hace un tiempo hice una macro que consultaba el estado de una postulacion a bonos del Sence y devolvía la respuesta en la misma hoja (nos facilitaba bastante el trabajo ya que eran 2500 personas que se debían chequear mensualmente cuyo código es : (1)

Luego del éxito de esta macro quise replicar algo similar en la pagina del servicio impuestos internos , ya que me pasaron un listado de propiedades que debia revisar si las contribuciones estaban canceladas , pero la pagina no solo es de ingresar datos sino que se debe seleccionar de una lista despegable hasta el momento llevo lo siguiente, pero no logro pasar la siguiente linea

IE.document.getElementByClassName("SELPREDIO").Value = "1424"



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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
(1)Private Sub IE_Autiomation()
 
    Dim r, h , inicio  As Integer
 
    Dim x As String
 
    Dim i As Long
 
    Dim IE As Object
 
    Dim objElement As Object
 
    Dim objCollection As Object
 
 
    ' Creamos internet explorer como objeto
 
    Set IE = CreateObject("InternetExplorer.Application")
 
 
    ' Hacemos visible el navegador
 
    IE.Visible = True
 
 
    ' Indicamos la pagina de navegacion
 
    IE.Navigate "https://aplicaciones.sence.cl/ValidaRequisitoSej/"
 
    ' Le indicamos que debe esperar mientras carga el navegador
 
    Do While IE.Busy
 
        Application.Wait DateAdd("s", 1, Now)
 
    Loop
 
r = 1
inicio = 1
For r = 1 To 5   ' iniciamos el recorrido de celdas 
 
    Application.StatusBar = "Estamos en proceso de ejecución , favor espere..."   ' Mensaje de estado de ejecucion
 
    IE.document.getElementById("rut").Value = Sheets("hoja1").Cells(r, 1)  ' en la pagina en cuestion el formulario a rellenar tiene como id "rut" y le asignamos el valor de la celda en cuestion
 
    Set objCollection = IE.document.getElementsByTagName("input")
 
    i = 0
 
    While i < objCollection.Length
 
        If objCollection(i).Name = "s" Then
 
            ' Set text for search
 
            objCollection(i).Value = "excel vba"
 
        Else
 
            If objCollection(i).Type = "submit" And objCollection(i).Name = "" Then
 
                ' "Search" button is found
 
                Set objElement = objCollection(i)
 
            End If
 
        End If
 
        i = i + 1
    Wend
    objElement.Click    ' click button to search
 
    ' Wait while IE re-loading...
 
    Do While IE.Busy
     'rescatar datos
     ' SELECCIONAR PANTALLA
      IE.ExecWB 17, 0
    ' COPIO LO SELECCIONADO
      IE.ExecWB 12, 2
 
     Sheets("hoja2").Select
     Range("a1").Select
    ' PEGO LO COPIADO
      ActiveSheet.PasteSpecial Format:="HTML", link:=False, NoHTMLFormatting:=True
        Application.Wait DateAdd("s", 1, Now)
 
     ' RESCATE DE RESPUESTA
     ' Cambiar hoja para pegar respuesta
               h = 0
               Dim texto As String
               texto = ""
               For h = 1 To 17
               Sheets("hoja2").Select
 
 
               Range("A" & h).Select
 
               ' ActiveCell.FormulaR1C1 = Left(ActiveCell.Offset(0, -4).Value, 5)
               'MsgBox (Left(ActiveCell.Value, 5))
                    If Left(ActiveCell.Value, 5) = "Usted" Then
                        'MsgBox ("entre")
 
                      texto = texto + ActiveCell.Value
 
                    End If
               Next h
                Sheets("Hoja1").Select
                Range("B" & r).Select
                ActiveCell.Value = texto
    Loop
 
 
    ' Show IE
 
    IE.Visible = True
 
 
    ' Clean up
 
   ' Set IE = Nothing
 
    Set objElement = Nothing
 
    Set objCollection = Nothing
 
 
    Application.StatusBar = " listo "
 
Next r
 
End Sub


Luego del éxito de esta macro quise replicar algo similar en la pagina del servicio impuestos internos , ya que me pasaron un listado de propiedades que debia revisar si las contribuciones estaban canceladas , pero la pagina no solo es de ingresar datos sino que se debe seleccionar de una lista despegable hasta el momento llevo lo siguiente, pero no logro pasar la siguiente linea

IE.document.getElementByClassName("SELPREDIO").Value = "1424"

si alguien entiende cual es el error les agradecería bastante , desde ya muchas gracias.

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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
(2) Private Sub IE_Autiomation()
 
    Dim r, h   As Integer
 
    Dim x As String
 
    Dim i As Long
 
    Dim IE As Object
 
    Dim objElement As Object
 
    Dim objCollection As Object
 
 
    ' Create InternetExplorer Object
 
    Set IE = CreateObject("InternetExplorer.Application")
 
 
    ' Visualizar internet explorer
 
    IE.Visible = True
 
 
    ' Send the form data To URL As POST binary request
 
    IE.Navigate "https://zeus.sii.cl/avalu_cgi/br/brcc00.sh"
 
 
 
    ' Wait while IE loading...
 
    Do While IE.Busy
 
        Application.Wait DateAdd("s", 1, Now)
 
    Loop
 
 
 
r = 1
Dim inicio As Integer
inicio = 1
For r = 1 To 1
 
    Application.StatusBar = "En ejecución , favor espere..."
 
    Private Sub IE_Autiomation()
 
    Dim r, h   As Integer
 
    Dim x As String
 
    Dim i As Long
 
    Dim IE As Object
 
    Dim objElement As Object
 
    Dim objCollection As Object
 
 
    ' Create InternetExplorer Object
 
    Set IE = CreateObject("InternetExplorer.Application")
 
 
    ' Visualizar internet explorer
 
    IE.Visible = True
 
 
    ' Send the form data To URL As POST binary request
 
    IE.Navigate "https://zeus.sii.cl/avalu_cgi/br/brcc00.sh"
 
 
 
    ' Wait while IE loading...
 
    Do While IE.Busy
 
        Application.Wait DateAdd("s", 1, Now)
 
 
 
    Loop
 
 
 
r = 1
Dim inicio As Integer
inicio = 1
For r = 1 To 1
 
    Application.StatusBar = "En ejecución , favor espere..."
 
    IE.document.getElementByClassName("SELPREDIO").Value = "1424"
    IE.document.getElementByTagName("SELCOMUNA").Value = Sheets("hoja1").Cells(r, 2)
    IE.document.getElementByTagName("SELMANZANA").Value = Sheets("hoja1").Cells(r, 3)
    IE.document.getElementByTagName("SELPREDIO").Value = Sheets("hoja1").Cells(r, 4)
 
    Set objCollection = IE.document.getElementsByTagName("input")
 
    i = 0
 
    While i < objCollection.Length
 
        If objCollection(i).Name = "s" Then
 
            ' Set text for search
 
            objCollection(i).Value = "excel vba"
 
        Else
 
            If objCollection(i).Type = "submit" And objCollection(i).Name = "" Then
 
                ' "Search" button is found
 
                Set objElement = objCollection(i)
 
            End If
 
        End If
    IE.document.getElementByTagName("SELCOMUNA").Value = Sheets("hoja1").Cells(r, 2)
    IE.document.getElementByTagName("SELMANZANA").Value = Sheets("hoja1").Cells(r, 3)
    IE.document.getElementByTagName("SELPREDIO").Value = Sheets("hoja1").Cells(r, 4)
 
    Set objCollection = IE.document.getElementsByTagName("input")
 
    i = 0
 
    While i < objCollection.Length
 
        If objCollection(i).Name = "s" Then
 
            ' Set text for search
 
            objCollection(i).Value = "excel vba"
 
        Else
 
            If objCollection(i).Type = "submit" And objCollection(i).Name = "" Then
 
                ' "Search" button is found
 
                Set objElement = objCollection(i)
 
            End If
 
        End If
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder