Using XML in VBA
From Ribbon Commander Documentation
Revision as of 23:15, 14 March 2013 by Rxdff15551 bb53 (Talk | contribs)
Introduction
Dynamic RibbonX controls are both
- Serializable to XML
- Instantiatable from XML
Serializing to XML
Public Sub SerializingButton() ' Create a new button Dim myButton As rxButton Set myButton = New rxButton ' Build up state With myButton .label = "My Button" .enabled = rxTrue .supertip = "My button supertip" ' Serialize to XML Debug.Print .XML End With End Sub
The VBA code above prints out the following XML code to the debug window:
<button supertip="My button supertip" enabled="true" label="My Button"></button>
Instantiating from XML
Public Sub InstantiateButtonFromXML()
' Create a new button
Dim myButton As rxButton
Set myButton = New rxButton
myButton.readXml "<button supertip=""My button supertip"" enabled=""true"" label=""My Button""/>"
Debug.Print "supertip=[" & myButton.supertip & "], " & _
"enabled=[" & (myButton.Enabled = rxTrue) & "], " & _
"label=[" & myButton.Label & "]"
End Sub
The VBA code above prints out the following XML code to the debug window:
supertip=[My button supertip], enabled=[True], label=[My Button]
A more complete example
Public Sub CompleteExample()
' Create a new rxCustomUI
Dim myCustomUI As rxCustomUI
Set myCustomUI = rxCustomUI.Create("my_test_context")
With myCustomUI
With .ribbon.tabs.Add(New rxTab)
.Label = "My Tab"
.Visible = rxTrue
With .groups.Add(New rxGroup)
.Label = "Group 1"
With .Buttons.Add(New rxButton)
.Label = "Button1"
.OnAction = myCustomUI.make_delegate("Callback1")
End With
With .Buttons.Add(New rxButton)
.Label = "Button2"
.getEnabled = myCustomUI.make_delegate("Callback2")
End With
End With
With .groups.Add(New rxGroup)
.Label = "Group 2"
With .Buttons.Add(New rxButton)
.Label = "Button3"
.getKeytip = myCustomUI.make_delegate("Callback3")
End With
With .Buttons.Add(New rxButton)
.Label = "Button4"
.getShowImage = myCustomUI.make_delegate("Callback4")
.ID = "button4"
End With
End With
End With
' Cache the xml state of 'myCustomUI' and print it out in the debug window
Dim sXml As String
sXml = .SerializeToXML
Debug.Print sXml
End With
End Sub
<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui"> <ribbon> <tabs> <tab id="RX4C5E51-2222-4D76-AEF5-97D7460E8FC9" visible="true" label="My Tab"> <group id="RX4F6096-0B31-42F9-B299-823510E5C304" label="Group 1"> <button label="Button1" id="RXE10CA5-9197-4FF7-A7BA-5ECEB4DF6D6C" onAction="Callback1"></button> <button label="Button2" id="RXE269D3-0CB2-4031-90D2-E91304BC5D8F" getEnabled="Callback2"></button> </group> <group id="RX6A4144-9F73-4307-8F26-B2B107764E08" label="Group 2"> <button label="Button3" id="RX8480FB-8F17-4489-AA16-76C4178826EC" getKeytip="Callback3"></button> <button label="Button4" id="button4" getShowImage="Callback4"></button> </group> </tab> </tabs> </ribbon> </customUI>