![]() |
| Previous Top Next |
Visual Basic |
The following Visual Basic example is the code for a macro in an Excel worksheet (screenshot below). The macro has been assigned to the button Run Expressions. On clicking the button, the Visual Basic code is executed.

Code sample
The Visual Basic code below uses the XQuery interface.
Sub CommandButton1_Click()
Set objAltovaXML = CreateObject("AltovaXML.Application")
objAltovaXML.XQuery.XQueryFromText = Sheet1.Cells(2, 1)
Sheet1.Cells(2, 2) = objAltovaXML.XQuery.ExecuteAndGetResultAsString
objAltovaXML.XQuery.InputXMLFromText = Sheet1.Cells(3, 1)
objAltovaXML.XQuery.XQueryFromText = "translate(node, ';-', '. ')"
Sheet1.Cells(3, 2) = objAltovaXML.XQuery.ExecuteAndGetResultAsString
objAltovaXML.XQuery.InputXMLFromText = "<a myAttr='A code-generated string'/>"
objAltovaXML.XQuery.XQueryFromText = "string(/a/@*)"
Sheet1.Cells(4, 2) = objAltovaXML.XQuery.ExecuteAndGetResultAsString
End Sub
On clicking the button Run Expressions in the Excel worksheet, the following three XQuery instructions are executed:
| 1. | The input for the XQueryFromText property is an XQuery expression taken as text from the Excel worksheet cell 2A. The ExecuteAndGetResultAsString property executes the XQuery expression and places the result in the Excel worksheet cell 2B. |
| 2. | The input for the InputXMLFromText property is an XML fragment taken from the Excel worksheet cell 3A. The XQuery expression is given to the XQueryFromText property directly in the code. The result is placed in the Excel worksheet cell 3B. |
| 3. | The InputXMLFromText property creates an XML tree from the XML fragment provided to it. The XQuery expression is given to the XQueryFromText property directly in the code, and the result is placed in the Excel worksheet cell 4B. |
|