Difference between revisions of "A 'hello world' VBA program"

From Ribbon Commander Documentation
Jump to: navigation, search
(Code Analysis)
Line 39: Line 39:
  
 
<syntaxhighlight lang="vb">
 
<syntaxhighlight lang="vb">
Dim i As Long
+
' Get a reference to the rxRibbon object of our rxCustomUI instance
 +
Dim myRibbon As rxRibbon
 +
Set myRibbon = myCustomUI.ribbon
 +
</syntaxhighlight>
 +
 
 +
Each rxCustomUI object owns a unique rxRibbon object. Here, we are holding on to the rxRibbon object of myCustomUI
 +
 
 +
 
 +
<syntaxhighlight lang="vb">
 +
' Get a reference to the rxRibbon object of our rxCustomUI instance
 +
Dim myRibbon As rxRibbon
 +
Set myRibbon = myCustomUI.ribbon
 
</syntaxhighlight>
 
</syntaxhighlight>

Revision as of 17:16, 10 March 2013

Creating a tab

  • Enter the code below in a standard VBA module
  1. Public Sub CreateMyUI()
  2.  
  3.     ' Get a reference to the default rxCustomUI instance
  4.     Dim myCustomUI As rxCustomUI
  5.     Set myCustomUI = rxCustomUI.defaultInstance
  6.  
  7.     ' Get a reference to the rxRibbon object of our rxCustomUI instance
  8.     Dim myRibbon As rxRibbon
  9.     Set myRibbon = myCustomUI.ribbon
  10.  
  11.     ' Create a new tab
  12.     Dim myTab As rxTab
  13.     Set myTab = myRibbon.tabs.Add(New rxTab)
  14.  
  15.  
  16.     ' Give the new tab a label
  17.     myTab.Label = "My First Tab"
  18.  
  19.  
  20.     ' Render the UI
  21.     myCustomUI.Refresh
  22.  
  23. End Sub
  • Run the sub to create an empty tab labeled 'My First Tab'
    EmptyTab.png

Code Analysis

Dim myCustomUI As rxCustomUI
Set myCustomUI = rxCustomUI.defaultInstance

rxCustomUI is at the top of the object model hierarchy. Here, we are holding on to the default rxCustomUI instance for the current office application session.


' Get a reference to the rxRibbon object of our rxCustomUI instance
Dim myRibbon As rxRibbon
Set myRibbon = myCustomUI.ribbon

Each rxCustomUI object owns a unique rxRibbon object. Here, we are holding on to the rxRibbon object of myCustomUI


' Get a reference to the rxRibbon object of our rxCustomUI instance
Dim myRibbon As rxRibbon
Set myRibbon = myCustomUI.ribbon