Difference between revisions of "Using XML in VBA"

From Ribbon Commander Documentation
Jump to: navigation, search
Line 51: Line 51:
  
 
== A more complete example ==
 
== A more complete example ==
 +
 +
<syntaxhighlight lang="xml">
 +
<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>
 +
</syntaxhighlight>

Revision as of 00:14, 15 March 2013

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

  1. Public Sub InstantiateButtonFromXML()
  2.  
  3.     ' Create a new button
  4.     Dim myButton As rxButton
  5.     Set myButton = New rxButton
  6.  
  7.     myButton.readXml "<button supertip=""My button supertip"" enabled=""true"" label=""My Button""/>"
  8.  
  9.     Debug.Print "supertip=[" & myButton.supertip & "], " & _
  10.                 "enabled=[" & (myButton.Enabled = rxTrue) & "], " & _
  11.                 "label=[" & myButton.Label & "]"
  12.  
  13. 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

<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>