PDA

View Full Version : [SOLVED:] Toolbar for add-ins created



magnel
10-16-2013, 07:28 AM
Hello John,

I am using PowerPoint 2010, I have gathered a few macros code given by you and have created addins for the same. I wanted to gather all the addin in a toolbar, but I have two set of code for the toolbar which works perfectly when used separately, but I want to merge both of them, so that I have combination of button and drop down button in the toolbar. Below are the two set of codes.

Set 1--------------------------

Sub Auto_Open1()
Dim oToolbar As CommandBar
Dim oButton As CommandBarButton
Dim MyToolbar As String


MyToolbar = "Toolbar"


On Error Resume Next


Set oToolbar = CommandBars.Add(Name:=MyToolbar, _
Position:=msoBarFloating, Temporary:=True)
If err.Number <> 0 Then
Exit Sub
End If


On Error GoTo errorhandler


'Button 1 ====================================


Set oButton = oToolbar.Controls.Add(Type:=msoControlButton)


With oButton
.DescriptionText = "Description"
.Caption = "Caption"
.OnAction = "MacroName"
.Style = msoButtonIconAndCaption
.FaceId = ###
End With

'Button 2 ====================================


Set oButton = oToolbar.Controls.Add(Type:=msoControlButton)


With oButton
.DescriptionText = "Description"
.Caption = "Caption"
.OnAction = "MacroName"
.Style = msoButtonIconAndCaption
.FaceId = ###
End With


oToolbar.Top = 150
oToolbar.Left = 150
oToolbar.Visible = True


NormalExit:
Exit Sub


errorhandler:
'Just in case there is an error
MsgBox err.Number & vbCrLf & err.Description
Resume NormalExit:

End Sub



Set 2--------------------------

Sub Auto_Open2()
Dim myMainMenuBar As CommandBar
Dim myCustomMenu As CommandBarControl
Dim myTempMenu As CommandBarControl


On Error Resume Next
Application.CommandBars.ActiveMenuBar.Controls("This name").Delete
On Error GoTo errorhandler
Set myMainMenuBar = Application.CommandBars.ActiveMenuBar


Set myCustomMenu = myMainMenuBar.Controls.Add(Type:=msoControlPopup, _
before:=3)
myCustomMenu.Caption = "This name"


'Button 1 ====================================


Set myTempMenu = myCustomMenu.Controls.Add(Type:=msoControlButton)
With myTempMenu

.Caption = "Whatever"
.OnAction = "Whatever"
End With


'Button 2 ====================================

Set myTempMenu = myCustomMenu.Controls.Add(Type:=msoControlButton)
With myTempMenu

.Caption = "Something else"
.OnAction = "Something_else"
End With


'repeat these as often as you wish

Exit Sub
errorhandler:
MsgBox "Sorry there's been an error " & err.Description, vbCritical
End Sub





Please can you take a look at the code and help me merge both sets into one.

Thanks,
Rafael

John Wilson
10-16-2013, 08:14 AM
This is old legacy code which is not needed or sensible in 2010.

Create your pptm file calling the macros myMacro1, myMacro2 etc. Save and close PPT

Download the Custom UI EDitor tool (http://openxmldeveloper.org/blog/b/openxmldeveloper/archive/2010/08/10/23248.aspx)

Use it to open the pptm file

Insert > Office 2007 Custum UI Part (NOT 2010)

Paste in the code below and save

Open the pptm in PowerPoint

code to paste

<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui">
<ribbon startFromScratch="false">
<tabs>
<tab id="customTab1" label="Label Name" >
<group id="Group1" label="Label Name" >
<menu id="menu2" imageMso="TableIndexes" size="large" label="Macros" >
<button id="MenubuttA" label="Macro1" imageMso="AppointmentColor1" onAction="myMacro1"/>
<button id="MenubuttB" label="Macro2" imageMso="AppointmentColor2" onAction="myMacro2"/>
</menu>
<button id="customButton1" label="Macro3" imageMso="AppointmentColor3" onAction ="myMacro3" />
<button id="customButton2" label="Macro4" imageMso="AppointmentColor4" onAction ="myMacro4" />
</group>
</tab>
</tabs>
</ribbon>
</customUI>

Example file (http://www.pptalchemy.co.uk/Downloads/toolbar.pptm)

magnel
10-16-2013, 11:51 AM
That is really great John, had never used Custom UI Editor tool earlier, just downloaded and it was really easy to use. It was really very helpful.

Paul_Hossler
10-22-2013, 07:39 AM
There is an Office 2007 Ribbon UI forum here with a lot of information and tips to using the Fluent CustomUI interface

Also a lot of 2010 material and links also


Paul

SoftMast
10-31-2013, 11:48 AM
Working Great for me, Tnx for share!