Utilizo uma Macro VBA para gerar um arquivo XML para cada linha do excel.
Porém, preciso que para células que estão vazias, a Macro VBA desconsidere e não inclua no arquivo.
Segue abaixo.
Sub ExportToXml()
Dim linha As Long, coluna As Long, colunas As Long
linha = 2
colunas = ActiveSheet.UsedRange.Columns.Count
With ActiveSheet
Do While Not IsEmpty(.Cells(linha, 1))
Set fs = CreateObject("Scripting.FileSystemObject")
Set a = fs.CreateTextFile(Cells(linha, 1).Value & ".xml", True)
'cria as primeiras linhas
a.WriteLine ("<?xml file>")
a.WriteLine ("<IncluirRelatorioFinanceiro>")
coluna = 1
If Len(RTrim(.Cells(linha, coluna).Value)) > 0 Then
a.Write (Chr(9) & _
"<NumeroDocumento>" & _
RTrim(.Cells(linha, coluna).Value) & _
"</NumeroDocumento>" & Chr(13))
a.WriteLine
End If
coluna = 2
If Len(RTrim(.Cells(linha, coluna).Value)) > 0 Then
a.Write (Chr(9) & _
"<NomeTomadorServico>" & _
RTrim(.Cells(linha, coluna).Value) & _
"</NomeTomadorServico>" & Chr(13))
a.WriteLine
End If
coluna = 3
If Len(RTrim(.Cells(linha, coluna).Value)) > 0 Then
a.Write (Chr(9) & _
"<Cidade>" & _
RTrim(.Cells(linha, coluna).Value) & _
"</Cidade>" & Chr(13))
a.WriteLine
End If
coluna = 4
If Len(RTrim(.Cells(linha, coluna).Value)) > 0 Then
a.Write (Chr(9) & _
"<DataInicio>" & _
RTrim(.Cells(linha, coluna).Value) & _
"</DataInicio>" & Chr(13))
a.WriteLine
End If
coluna = 5
If Len(RTrim(.Cells(linha, coluna).Value)) > 0 Then
a.Write (Chr(9) & _
"<DataConclusao>" & _
RTrim(.Cells(linha, coluna).Value) & _
"</DataConclusao>" & Chr(13))
a.WriteLine
End If
coluna = 6
If Len(RTrim(.Cells(linha, coluna).Value)) > 0 Then
a.Write (Chr(9) & _
"<Valor>" & _
RTrim(.Cells(linha, coluna).Value) & _
"</Valor>" & Chr(13))
End If
linha = linha + 1
'finaliza o arquivo
a.Close
Loop
End With
MsgBox "Exportação concluída!"
End Sub