Excel - READ LOOP XML ERROR

 
Vista:

READ LOOP XML ERROR

Publicado por Osmel (1 intervención) el 24/02/2015 16:18:44
Hola, necesito ayuda. Tengo un listado en la columna 3 de direcciones xml, necesito leer ciertos nodos pero cuando el for next hace una ronda me sale el error "Variable de objeto o bloque With no establecido". Alguien me ayude por favor.


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
Sub LeerXml()
 
       ' Worksheets("xml").Activate ' aun no funciona esta referencia
       Sheets("xml").Activate
 
      ' optimizar macro
      Application.ScreenUpdating = False
      Application.Calculation = xlCalculationManual
      Application.EnableEvents = False
      ActiveSheet.DisplayPageBreaks = False
 
      ' variables para buscar existencia
      Dim x As Long
      Dim NumRows As Long
      Dim Ruta As String
      Dim Mruta As String
 
      i = 2 ' filas superiores que no se ocupan.
 
      ' variables para extraer campos xml
 
 
      Dim mifolio As String
      Dim mivalor As String
      Dim mifecha As String
 
 
      ' Establecer numrows = número de filas de datos.
      NumRows = Range("C6", Range("C6").End(xlDown)).Rows.Count
 
      ' Seleccionar celda a1.
      ' Range("K6:K99999").ClearContents
      ' Range("J6").Select
      ' Establecer valor "For" para que vaya de bucle el bucle durante "numrows" veces.
      For x = 1 To NumRows
 
            If Cells(x + i, 3).Value <> Empty Then
                        Application.StatusBar = "Realizando proceso " & x & " de " & NumRows & " registros ..."
            End If
 
 
 
         ' Ruta = "C:\Users\Seven\Documents\Osmel\xml\R00820.xml"
                    Dim elements As Object
                    Dim xmldoc As MSXML2.DOMDocument
 
                    Set xmldoc = CreateObject("MSXML2.DOMDocument")
                    Ruta = Cells(x + i, 3).Value
                    xmldoc.Load (Ruta)
                    Set elements = xmldoc.getElementsByTagName("cfdi:Comprobante")
                    mifolio = xmldoc.SelectSingleNode("//cfdi:Comprobante").Attributes.getNamedItem("folio").Text
                    mivalor = xmldoc.SelectSingleNode("//cfdi:Comprobante").Attributes.getNamedItem("total").Text
                    mifecha = xmldoc.SelectSingleNode("//cfdi:Comprobante").Attributes.getNamedItem("fecha").Text
 
                    Cells(x + i, 7).Value = mifolio
                    Cells(x + i, 8).Value = mivalor
                    Cells(x + i, 9).Value = Left(mifecha, 10)
 
                    Set xmldoc = Nothing
                    Set elements = Nothing
                    Ruta = ""
 
 
      Next
      Application.StatusBar = "Completado"
 
      Application.ScreenUpdating = True
      Application.Calculation = xlCalculationAutomatic
      Application.EnableEvents = True
      ActiveSheet.DisplayPageBreaks = True
      Application.CutCopyMode = False
 
   End Sub
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