Topic
IC4NOTICE: developerWorks Community will be offline May 29-30, 2015 while we upgrade to the latest version of IBM Connections. For more information, read our upgrade FAQ.
1 reply Latest Post - ‏2012-09-25T17:08:39Z by SystemAdmin
Enoon
Enoon
1 Post
ACCEPTED ANSWER

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
    SystemAdmin
    746 Posts
    ACCEPTED ANSWER

    Re: problem pass string variable to a xPath in VBA

    ‏2012-09-25T17:08:39Z  in response to Enoon
    
    aPath = 
    "//CasaPiezos[CasaPiezo/CasaPiezoRdg/" & dataName & 
    "]"