• 1 reply
  • Latest Post - ‏2012-09-25T17:08:39Z by SystemAdmin
1 Post

Pinned topic problem pass string variable to a xPath in VBA

‏2012-09-25T07:48:46Z |
I'm writing a function in vba which can take in string parameters, and use it in xPath
thus query specificed data.
Public Function GetVal(ByVal refNum As String, ByVal jobNum As String, ByVal readingNum As String, ByVal dataName As String) As String
Dim xDoc As MSXML2.DOMDocument
Dim xmlFilePath As String: xmlFilePath = ThisWorkbook.Path & "\1.xml"
Dim apath as String
If Not xDoc.Load(xmlFilePath) Then
MsgBox ("Failed to load XML file."), vbCritical, "Sub Aborted"
Exit Function
End If

aPath = "//CasaPiezos[CasaPiezo/CasaPiezoRdg/'dataname'"
'above is line not working i replace the variable with string it works, but string name canot
'those quotes driving me crazy.....
GetVal = xDoc.SelectSingleNode(aPath).Text
End Function
Updated on 2012-09-25T17:08:39Z at 2012-09-25T17:08:39Z by SystemAdmin
  • SystemAdmin
    746 Posts

    Re: problem pass string variable to a xPath in VBA

    aPath = 
    "//CasaPiezos[CasaPiezo/CasaPiezoRdg/" & dataName &