
Convertir este codigo en una funcion !!Mil gracias
Publicado por BELINDA (3 intervenciones) el 09/05/2017 20:09:47
Publicado por BELINDA (2 intervenciones) el 09/05/2017 18:18:29
Buenas amigos ,ojala puedan ayudarme tengo este código de visual basic que lo encontre en internet para buscar dni , pero quisiera convertirlo en una function , por ejmplo function buscardni, poner esta formula en una celda y que me arroje el resultado que es el nombre y direccion de la persona.Este el codigo ..Mil gracias
Abajo dejo la function creada
No se mucho de programación pero estaba pensando algo así pero no tengo el resultado deseado..En que he fallado?
Buenas amigos ,ojala puedan ayudarme tengo este código de visual basic que lo encontre en internet para buscar dni , pero quisiera convertirlo en una function , por ejmplo function buscardni, poner esta formula en una celda y que me arroje el resultado que es el nombre y direccion de la persona.Este el codigo ..Mil gracias
Abajo dejo la function creada
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
Sub buscardni(NroDoc As String)
Dim URL As String
Dim IE As InternetExplorer
Dim HTMLdoc As HTMLDocument
Dim TDelements As IHTMLElementCollection
Dim TDelement As HTMLTableCell
Dim r As Long
Dim HTMLDoc2 As MSHTML.HTMLDocument
Dim TDelements2 As IHTMLElementCollection
Range("b5:b10").ClearContents
Set IE = New InternetExplorer
With IE
.navigate "http://votoinformado.pe/voto/miembro_mesa.aspx"
.Visible = False
While .Busy Or .readyState <> READYSTATE_COMPLETE: DoEvents: Wend
.Document.getElementById("txtCongrDNI").Value = NroDoc
Application.DisplayAlerts = False
.Document.getElementById("btnCongrDNI").Click
Application.DisplayAlerts = True
End With
Set HTMLdoc = IE.Document
While IE.Busy Or IE.readyState <> READYSTATE_COMPLETE: DoEvents: Wend
Set HTMLDoc2 = IE.Document
While IE.Busy Or IE.readyState <> READYSTATE_COMPLETE: DoEvents: Wend
Set TDelements = HTMLDoc2.getElementsByTagName("Td")
For Each TDelement In TDelements
If r = 1 Then [b5].Value = TDelement.innerText
If r = 3 Then [b7].Value = TDelement.innerText
r = r + 1
Next
IE.Quit
Application.StatusBar = ""
End Sub
No se mucho de programación pero estaba pensando algo así pero no tengo el resultado deseado..En que he fallado?
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
function buscardni(NroDoc As String)as string
Dim URL As String
Dim IE As InternetExplorer
Dim HTMLdoc As HTMLDocument
Dim TDelements As IHTMLElementCollection
Dim TDelement As HTMLTableCell
Dim r As Long
Dim HTMLDoc2 As MSHTML.HTMLDocument
Dim TDelements2 As IHTMLElementCollection
Range("b5:b10").ClearContents
Set IE = New InternetExplorer
With IE
.navigate "http://votoinformado.pe/voto/miembro_mesa.aspx"
.Visible = False
While .Busy Or .readyState <> READYSTATE_COMPLETE: DoEvents: Wend
.Document.getElementById("txtCongrDNI").Value = NroDoc
Application.DisplayAlerts = False
.Document.getElementById("btnCongrDNI").Click
Application.DisplayAlerts = True
End With
Set HTMLdoc = IE.Document
While IE.Busy Or IE.readyState <> READYSTATE_COMPLETE: DoEvents: Wend
Set HTMLDoc2 = IE.Document
While IE.Busy Or IE.readyState <> READYSTATE_COMPLETE: DoEvents: Wend
Set TDelements = HTMLDoc2.getElementsByTagName("Td")
For Each TDelement In TDelements
If r = 1 Then [b5].Value = TDelement.innerText
If r = 3 Then [b7].Value = TDelement.innerText
r = r + 1
Next
IE.Quit
Application.StatusBar = ""
buscardni=r
End function
Valora esta pregunta


0