Sub GENERER_XML()
Dim derligne As Integer
Dim Chemin, Fichier As String
Dim TT_HT, TT_TVA, TT_TTC As Long
derligne = (Range("A" & Rows.Count).End(xlUp).Row) + 1
For Each Cell In Sheets("DEDUC").Range("C1:C" & derligne)
If Cell.Value = "Total" Then
TT_HT = Cells(Cell.Row, ((Cell.Column) + 1)).Value
TT_TVA = Cells(Cell.Row, ((Cell.Column) + 2)).Value
TT_TTC = TT_HT + TT_TVA
End If
Next
'--------------------------------------------
Dim objShell As Object, objFolder As Object, oFolderItem As Object
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.BrowseForFolder(&H0&, "Choisir un répertoire", &H1&)
On Error Resume Next
Set oFolderItem = objFolder.Items.Item
Chemin = oFolderItem.Path
'-----------------------------------------------------------------------------------------
Fichier = Chemin & "\FichierGen.xml"
Dim intFic As Integer
intFic = FreeFile
Open Fichier For Output As intFic
Print #intFic, "<?xml version="; 1#; "?>"
Print #intFic, "<DeclarationReleveDeduction xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"">"
Print #intFic, "<identifiantFiscal>" & Sheets("DEDUC").Range("C2").Value & "</identifiantFiscal>"
Print #intFic, "<annee>" & Sheets("DEDUC").Range("C3").Value & "</annee>"
Print #intFic, "<periode>" & Sheets("DEDUC").Range("C4").Value & "</periode>"
Print #intFic, "<regime>" & Sheets("DEDUC").Range("C5").Value & "</regime>"
Print #intFic, "<releveDeductions>"
For Each Cell In Range("A1:A" & derligne)
If Not IsEmpty(Cell.Value) And IsNumeric(Cell.Value) Then
Print #intFic, "<rd>"
Print #intFic, "<ord>" & Cells(Cell.Row, (Cell.Column)).Value & "</ord>"
Print #intFic, "<num>" & Cells(Cell.Row, (Cell.Column) + 1).Value & "</num>"
Print #intFic, "<des>" & Cells(Cell.Row, (Cell.Column) + 2).Value & "</des>"
Print #intFic, "<mht>" & Cells(Cell.Row, (Cell.Column) + 3).Value & "</mht>"
Print #intFic, "<tva>" & Cells(Cell.Row, (Cell.Column) + 4).Value & "</tva>"
Print #intFic, "<ttc>" & Cells(Cell.Row, (Cell.Column) + 5).Value & "</ttc>"
Print #intFic, "<refF>"
Print #intFic, "<if>" & Cells(Cell.Row, (Cell.Column) + 6).Value & "</if>"
Print #intFic, "<nom>" & Cells(Cell.Row, (Cell.Column) + 7).Value & "</nom>"
Print #intFic, "<ice>" & Cells(Cell.Row, (Cell.Column) + 8).Value & "</ice>"
Print #intFic, "</refF>"
Print #intFic, "<tx>" & Cells(Cell.Row, (Cell.Column) + 9).Value& & "</tx>"
Print #intFic, "<mp>"
Print #intFic, "<id>" & Cells(Cell.Row, (Cell.Column) + 10).Value & "</id>"
Print #intFic, "</mp>"
Print #intFic, "<dpai>" & Cells(Cell.Row, (Cell.Column) + 11).Value & "</dpai>"
Print #intFic, "<dfac>" & Cells(Cell.Row, (Cell.Column) + 12).Value & "</dfac>"
Print #intFic, "</rd>"
End If
Next
Print #intFic, "<rd>"
Print #intFic, "<Total Hors taxes>" & TT_HT & "</Total Hors taxes>"
Print #intFic, "<Total TVA>" & TT_TVA & "</Total TVA>"
Print #intFic, "<Total TTC>" & TT_TTC & "</Total TTC>"
Print #intFic, "<rd>"
Close intFic
End Sub