Recherche

Fonction VBA pour Extraire le contenue de balise XML

 Pour pouvoir extraire le contenu d'une balise XML à travers une fonction VBA, nous pouvons utiliser la fonction ci-dessous:

Public Function getXML(strxml As String, strElement As String) As String 'Fonction pour extraire une information à partir d'un fichier XML On Error GoTo errHandler If InStr(1, strxml, "<" & strElement & ">", vbTextCompare) > 0 And InStr(1, strxml, "</" & strElement & ">", vbTextCompare) > 0 Then 'trouver la chaine Dim intLeft As Integer Dim intright As Integer intLeft = InStr(1, strxml, "<" & strElement & ">", vbTextCompare) + Len(strElement) + 2 intright = InStr(1, strxml, "</" & strElement & ">", vbTextCompare) getXML = Mid(strxml, intLeft, intright - intLeft) Else GoTo badXML End If Exit Function badXML: MsgBox "Une erreur est apparue lors de l'extraction probablement à cause des cote", vbOKOnly Exit Function errHandler: MsgBox " Erreur d'extraction information a partir d'un XML information " & vbOKOnly & vbCancel Err.Clear Exit Function End Function

Aucun commentaire :

Enregistrer un commentaire