Vídeo recomendado
https://youtu.be/diWPPPhW-9E

Importar Automaticamente XMLs

Fórum para dúvidas sobre os fundamentos da linguagem de programação Visual Basic no contexto do VBA
mathgalvan
Acabou de chegar
Acabou de chegar
Mensagens: 3
Registrado em: Ter Jun 15, 2021 9:59 am

Importar Automaticamente XMLs

Mensagem por mathgalvan »

Olá Boa tarde Senhores Programadores. Sou novo por aqui e trabalho numa Transportadora.
Elaborei uma Planilha de Importação de XML e está rodando perfeitamente, porém, gostaria de programá-la para importar os XMLs automaticamente ao abrir a planilha e, ao importar, excluisse os XMLs da pasta que foram importados.
Estou usando essa progrmação para importar:

Sub importarNFe()

'Variaveis de manipulação de xml
Dim NFe As New MSXML2.DOMDocument

'Variaveis sem tipo difinido
Dim XMLS As Variant, XML As Variant

'Variaveis de Dicionário
Dim Notas As New Scripting.Dictionary

XMLS = AbrirXMLS

For Each XML In XMLS

NFe.Load (XML)

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 = NFe.SelectSingleNode("//xProd").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


Call LimparDadosNFe

Next XML

With Relatório

.Range("A" & .Range("A" & Rows.Count).End(xlUp).Row + 1).Resize(Notas.Count, UBound(Notas(i)) + 1).Value = Application.Transpose(Application.Transpose(Notas.Items))


End With
End Sub

Se podurem me ajudar, ficarei mto agradecido!!


Disable adblock

This site is supported by ads and donations.
If you see this text you are blocking our ads.
Please consider a Donation to support the site.


Responder