Option Explicit
'*************************************************************************
' einfach und geschmacklos durch Stringoperation
' zeilenweise
'*************************************************************************
Private Sub StreamIt()
Dim Meldung As Variant
Meldung = StringIt("C:\Temp\Forumtest.xml", _
"Stefan", "Telefonnummer")
MsgBox Meldung
End Sub
Private Function StringIt( _
ByVal Dateipfad As String, _
ByVal SucheNach As String, _
ByVal FindeWert As String) As Variant
Dim strZeile As String
Open Dateipfad For Input As #1
Do Until EOF(1)
Line Input #1, strZeile
If InStr(strZeile, SucheNach) > 0 Then
Do While InStr(strZeile, FindeWert) = 0
Line Input #1, strZeile
Loop
strZeile = Mid(strZeile, InStr(strZeile, ">") + 1)
StringIt = Mid(strZeile, 1, InStr(strZeile, "<") - 1)
Close #1
Exit Function
End If
Loop
Close #1
End Function
Wenn du den Standard für XML einhältst, kannste auch
Option Explicit
'*************************************************************************
' im VBA Editor unter Verweise EINBINDEN !!!
' Microsoft XML v3.0 oder höher
'*************************************************************************
Private Sub TestIt()
Dim Meldung As Variant
Meldung = GetXmlNode("C:\Temp\Forumtest.xml", _
"eintrag", "Nachname", "Stefan", "Telefonnummer")
MsgBox Meldung
End Sub
Private Function GetXmlNode( _
ByVal Dateipfad As String, _
ByVal Kategorie As String, _
ByVal SucheNach As String, _
ByVal SucheWert As String, _
ByVal FindeWert As String) As Variant
Dim xmlDatei As DOMDocument
Dim oListe As IXMLDOMNodeList
Dim oKnoten As IXMLDOMNode
Set xmlDatei = New DOMDocument
xmlDatei.Load Dateipfad
Set oListe = xmlDatei.DocumentElement.SelectNodes(Kategorie)
For Each oKnoten In oListe
If oKnoten.SelectSingleNode(SucheNach).Text = SucheWert Then
GetXmlNode = oKnoten.SelectSingleNode(FindeWert).Text
Exit For
End If
Next
End Function
Die Fingerübung mit der Userform schaffst du selbst ;-)
|