subrahmanyam
New Member
- Joined
- Feb 21, 2015
- Messages
- 14
'UI Functionality
<customUI xmlns='http://schemas.microsoft.com/office/2009/07/customui'>
<ribbon>
<tabs>
<tab id="CustomTab" label="My Stuff">
<group id="Group1" label="Stuff">
<labelControl id="Label1" getLabel="getLabel1" />
<labelControl id="Label2" getLabel="getLabel2" />
<editBox id="EditBox1"
showLabel="true"
label="Number:"
onChange="EditBox1_Change"/>
<button id="Button1"
label="Calculator"
size="large"
onAction="ShowCalculator"
imageMso="Calculator" />
</group>
<group id="Group2" label="More Stuff">
<toggleButton id="ToggleButton1"
size="large"
imageMso="FileManageMenu"
label="Toggle Me"
onAction="ToggleButton1_Click" />
<separator id="sep1" />
<checkBox id="Checkbox1"
label="Checkbox"
onAction="Checkbox1_Change"/>
<comboBox id="Combo1"
label="Month"
onChange="Combo1_Change">
<item id="Month1" label="January" />
<item id="Month2" label="February"/>
<item id="Month3" label="March"/>
<item id="Month4" label="April"/>
<item id="Month5" label="May"/>
<item id="Month6" label="June"/>
<item id="Month7" label="July"/>
<item id="Month8" label="August"/>
<item id="Month9" label="September"/>
<item id="Month10" label="October"/>
<item id="Month11" label="November"/>
<item id="Month12" label="December"/>
</comboBox>
</group>
<group id="Group3" label="Built In Stuff">
<control idMso="Copy" label="Copy" />
<control idMso="Paste" label="Paste" enabled="true" />
<control idMso="WindowSwitchWindowsMenuExcel" label="Switch Window" />
<control idMso="Italic" />
<control idMso="Bold" />
<control idMso="FileOpen" />
</group>
<group id="Group4" label="Built In Stuff">
<button
id="b1"
imageMso="AutoDial"
label="View the phone log"
onAction="Macro1" />
<button
id="b2"
imageMso="AttachMenu"
label="Order office supplies..."
onAction="Macro1" />
<button
id="b3"
imageMso="BlogHomePage"
label="Quit for the day and go home"
screentip="Had enough?"
supertip="Click here if you would like to knock off early today. Your boss will be alerted, and he will reply via email within 10 minutes."
onAction="Macro1" />
</group>
</tab>
</tabs>
</ribbon>
</customUI>
''VBA Code
'Callback for Label1 getLabel
Sub getLabel1(control As IRibbonControl, ByRef returnedVal)
returnedVal = "Hello " & Application.UserName
End Sub
'Callback for Label2 getLabel
Sub getLabel2(control As IRibbonControl, ByRef returnedVal)
returnedVal = "Today is " & Date
End Sub
'Callback for EditBox1 onChange
Sub EditBox1_Change(control As IRibbonControl, text As String)
Dim squareRoot As Double
On Error Resume Next
squareRoot = Sqr(text)
If Err.Number = 0 Then
MsgBox "The square root of " & text & " is: " & squareRoot
Else
MsgBox "Enter a positive number.", vbCritical
End If
End Sub
'Callback for Button1 onAction
Sub ShowCalculator(control As IRibbonControl)
On Error Resume Next
Shell "calc.exe", vbNormalFocus
If Err.Number <> 0 Then MsgBox "Can't start calc.exe"
End Sub
'Callback for ToggleButton1 getPressed
Sub ToggleButton1_Click(control As IRibbonControl, ByRef returnedVal)
MsgBox "Toggle value: " & returnedVal
End Sub
'Callback for Checkbox1 onAction
Sub Checkbox1_Change(control As IRibbonControl, pressed As Boolean)
MsgBox "Checkbox value: " & pressed
End Sub
'Callback for Combo1 onChange
Sub Combo1_Change(control As IRibbonControl, text As String)
MsgBox text
End Sub
'Callback for Gallery1 onAction
Sub MonthSelected(control As IRibbonControl, _
id As String, index As Integer)
MsgBox "You selected " & id
End Sub
'Callback for Today onAction
Sub ShowToday(control As IRibbonControl)
MsgBox "Today is " & Date
End Sub
'Callback for gallery2 onAction
Sub OnAction(control As IRibbonControl, id As String, index As Integer)
MsgBox "You clicked Banjo Photo #" & index + 1
End Sub
Sub Macro1(control As IRibbonControl)
' Executed when Sheet1 is active
MsgBox "Greetings from the Sheet1 Macro", vbInformation
End Sub
Sub Macro2(control As IRibbonControl)
' Executed when Sheet2 is active
MsgBox "Hello from the Sheet2 Macro", vbCritical
End Sub
Sub Macro3(control As IRibbonControl)
' Executed when Sheet3 is active
MsgBox "Aloha from the Sheet3 Macro", vbQuestion
End Sub
<customUI xmlns='http://schemas.microsoft.com/office/2009/07/customui'>
<ribbon>
<tabs>
<tab id="CustomTab" label="My Stuff">
<group id="Group1" label="Stuff">
<labelControl id="Label1" getLabel="getLabel1" />
<labelControl id="Label2" getLabel="getLabel2" />
<editBox id="EditBox1"
showLabel="true"
label="Number:"
onChange="EditBox1_Change"/>
<button id="Button1"
label="Calculator"
size="large"
onAction="ShowCalculator"
imageMso="Calculator" />
</group>
<group id="Group2" label="More Stuff">
<toggleButton id="ToggleButton1"
size="large"
imageMso="FileManageMenu"
label="Toggle Me"
onAction="ToggleButton1_Click" />
<separator id="sep1" />
<checkBox id="Checkbox1"
label="Checkbox"
onAction="Checkbox1_Change"/>
<comboBox id="Combo1"
label="Month"
onChange="Combo1_Change">
<item id="Month1" label="January" />
<item id="Month2" label="February"/>
<item id="Month3" label="March"/>
<item id="Month4" label="April"/>
<item id="Month5" label="May"/>
<item id="Month6" label="June"/>
<item id="Month7" label="July"/>
<item id="Month8" label="August"/>
<item id="Month9" label="September"/>
<item id="Month10" label="October"/>
<item id="Month11" label="November"/>
<item id="Month12" label="December"/>
</comboBox>
</group>
<group id="Group3" label="Built In Stuff">
<control idMso="Copy" label="Copy" />
<control idMso="Paste" label="Paste" enabled="true" />
<control idMso="WindowSwitchWindowsMenuExcel" label="Switch Window" />
<control idMso="Italic" />
<control idMso="Bold" />
<control idMso="FileOpen" />
</group>
<group id="Group4" label="Built In Stuff">
<button
id="b1"
imageMso="AutoDial"
label="View the phone log"
onAction="Macro1" />
<button
id="b2"
imageMso="AttachMenu"
label="Order office supplies..."
onAction="Macro1" />
<button
id="b3"
imageMso="BlogHomePage"
label="Quit for the day and go home"
screentip="Had enough?"
supertip="Click here if you would like to knock off early today. Your boss will be alerted, and he will reply via email within 10 minutes."
onAction="Macro1" />
</group>
</tab>
</tabs>
</ribbon>
</customUI>
''VBA Code
'Callback for Label1 getLabel
Sub getLabel1(control As IRibbonControl, ByRef returnedVal)
returnedVal = "Hello " & Application.UserName
End Sub
'Callback for Label2 getLabel
Sub getLabel2(control As IRibbonControl, ByRef returnedVal)
returnedVal = "Today is " & Date
End Sub
'Callback for EditBox1 onChange
Sub EditBox1_Change(control As IRibbonControl, text As String)
Dim squareRoot As Double
On Error Resume Next
squareRoot = Sqr(text)
If Err.Number = 0 Then
MsgBox "The square root of " & text & " is: " & squareRoot
Else
MsgBox "Enter a positive number.", vbCritical
End If
End Sub
'Callback for Button1 onAction
Sub ShowCalculator(control As IRibbonControl)
On Error Resume Next
Shell "calc.exe", vbNormalFocus
If Err.Number <> 0 Then MsgBox "Can't start calc.exe"
End Sub
'Callback for ToggleButton1 getPressed
Sub ToggleButton1_Click(control As IRibbonControl, ByRef returnedVal)
MsgBox "Toggle value: " & returnedVal
End Sub
'Callback for Checkbox1 onAction
Sub Checkbox1_Change(control As IRibbonControl, pressed As Boolean)
MsgBox "Checkbox value: " & pressed
End Sub
'Callback for Combo1 onChange
Sub Combo1_Change(control As IRibbonControl, text As String)
MsgBox text
End Sub
'Callback for Gallery1 onAction
Sub MonthSelected(control As IRibbonControl, _
id As String, index As Integer)
MsgBox "You selected " & id
End Sub
'Callback for Today onAction
Sub ShowToday(control As IRibbonControl)
MsgBox "Today is " & Date
End Sub
'Callback for gallery2 onAction
Sub OnAction(control As IRibbonControl, id As String, index As Integer)
MsgBox "You clicked Banjo Photo #" & index + 1
End Sub
Sub Macro1(control As IRibbonControl)
' Executed when Sheet1 is active
MsgBox "Greetings from the Sheet1 Macro", vbInformation
End Sub
Sub Macro2(control As IRibbonControl)
' Executed when Sheet2 is active
MsgBox "Hello from the Sheet2 Macro", vbCritical
End Sub
Sub Macro3(control As IRibbonControl)
' Executed when Sheet3 is active
MsgBox "Aloha from the Sheet3 Macro", vbQuestion
End Sub