mathgalvan
25-06-2021 17:38:47
Boa Tarde. Estou usando essse código para mapear dados das notas fiscais do XML e quando a nota tem mais que 1 produto consegui puxar os produtos contido na nota, porém, não estou conseguindo puxar o valor correto do segundo, terceiro, quarto... produto para ambos vem o valor do primeiro produto. Alguém tem alguma sugestão?
For Each XML In XMLS
NFe.Load (XML)
Set Produtos = NFe.SelectNodes("//xProd")
For Each Produto In Produtos
i = i + 1
With DadosNFe
.Data = Left(NFe.SelectSingleNode("//dhEmi").Text, 10)
.Hora = Mid(NFe.SelectSingleNode("//dhEmi").Text, 12, 8)
.NºNFe = NFe.SelectSingleNode("//nNF").Text
.Série = NFe.SelectSingleNode("//serie").Text
.Posto = NFe.SelectSingleNode("//emit//xNome").Text
On Error Resume Next
.Fantasia = NFe.SelectSingleNode("//emit//xFant").Text
If xFant = "" Then
.Fantasia = ""
End If
.Produto = Produto.Text
.ValorUni = NFe.SelectSingleNode("//vUnCom").Text
.Litros = NFe.SelectSingleNode("//qCom").Text
.ValorTotal = NFe.SelectSingleNode("//vProd").Text
.CFOP = NFe.SelectSingleNode("//CFOP").Text
.NCM = NFe.SelectSingleNode("//NCM").Text
.Informações = NFe.SelectSingleNode("//infCpl").Text
Notas(i) = Array(i, .Data, .Hora, .NºNFe, .Série, .Posto, .Fantasia, .Produto, .ValorUni, .Litros, .ValorTotal, .CFOP, .NCM, .Informações)
End With
Next Produto
Call LimparDadosNFe
Next XML
For Each XML In XMLS
NFe.Load (XML)
Set Produtos = NFe.SelectNodes("//xProd")
For Each Produto In Produtos
i = i + 1
With DadosNFe
.Data = Left(NFe.SelectSingleNode("//dhEmi").Text, 10)
.Hora = Mid(NFe.SelectSingleNode("//dhEmi").Text, 12, 8)
.NºNFe = NFe.SelectSingleNode("//nNF").Text
.Série = NFe.SelectSingleNode("//serie").Text
.Posto = NFe.SelectSingleNode("//emit//xNome").Text
On Error Resume Next
.Fantasia = NFe.SelectSingleNode("//emit//xFant").Text
If xFant = "" Then
.Fantasia = ""
End If
.Produto = Produto.Text
.ValorUni = NFe.SelectSingleNode("//vUnCom").Text
.Litros = NFe.SelectSingleNode("//qCom").Text
.ValorTotal = NFe.SelectSingleNode("//vProd").Text
.CFOP = NFe.SelectSingleNode("//CFOP").Text
.NCM = NFe.SelectSingleNode("//NCM").Text
.Informações = NFe.SelectSingleNode("//infCpl").Text
Notas(i) = Array(i, .Data, .Hora, .NºNFe, .Série, .Posto, .Fantasia, .Produto, .ValorUni, .Litros, .ValorTotal, .CFOP, .NCM, .Informações)
End With
Next Produto
Call LimparDadosNFe
Next XML