Results 1 to 5 of 5

Thread: Toolbar for add-ins created

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1

    Toolbar for add-ins created

    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
    Last edited by SamT; 10-17-2013 at 06:25 AM. Reason: Formatted Code with # button

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •