Consulting

Results 1 to 2 of 2

Thread: PowerPoint VBA to get value from Ribbon Control

  1. #1
    VBAX Newbie
    Joined
    Nov 2021
    Posts
    1
    Location

    Post PowerPoint VBA to get value from Ribbon Control

    Hi,
    I am a bit new to PowerPoint VBA and wondering if its possible to Design a ribbon addin with either dropdown list or combo box and then use the values to run some sub routine.
    So I have created PowerPoint Ribbon Addin with a DropDown with items showing as "Depart 1", "Depart 2" & "Depart 3" and then one button to say import excel. So Idea is user can first select which department they want to prepare the slides for. Once the department is selected then they can run the report which will copy the charts from the designated excel.
    Below code is an example to show what I am trying to do. In this when I select department in drop down list; I get the message which department is selected from Drop Down. But when I want to use that as variable, my code did not recognise it.

    Below is XML code I am having for Ribbon Addin:


       <ribbon>
         <tabs>
           <tab id="CustomTab" label="TestLabel">
            <group id="SampleGroup" label="BU Selection">   
            <dropDown id="DdropDown" label="Select Dept" onAction="DReportSelection" getSelectedItemIndex = "DropDown_OnGetSelectedItemIndex">
       <item id="item1" label="Depart 1" />
       <item id="item2" label="Depart 2" />
       <item id="item3" label="Depart 3" />
             </dropDown>
             </group >
    <group id="SampleGroup1" label="TestLabel">
               <button id="Button" label="Import Excel" imageMso="MicrosoftExcel" screentip="Import Data from Excel" size="large" onAction="ExcelImport" />
             </group >
           </tab>
         </tabs>
       </ribbon>
     </customUI>
    Below is VBA I am having in my presentation.

    Sub BUReportSelection(control As IRibbonControl, ID As String, selectedindex As Variant)
    Dim department As String
    department = Choose(selectedindex + 1, "Depart 1", "Depart 2", "Depart 3")
     
    MsgBox department & " is selected ", vbInformation
    End Sub
    ----------------------------------------------------------------------------------------
    Sub ExcelImport()
     
    If department = "Depart 1" Then
    Call Macro4Department 1
    End If
    If department = "Depart 2" Then
    Call Macro4Department 2
    End If
    If department = "Depart 3" Then
    Call Macro4Department 3
    End If
    End Sub
    Please note above code is just to demonstrate what I am trying to do.
    Thanks for your Help in advance.
    Andy

  2. #2
    VBAX Sage
    Joined
    Apr 2007
    Posts
    8,028
    Location
    Maybe you can integrate something like this

    Option Explicit
    
    Dim ddIndex As Long
    Dim ddDept As String
    
    'Callback for DdropDown onAction
    Sub DReportSelection(control As IRibbonControl, id As String, index As Integer)
        ddIndex = index
    End Sub
    
    'Callback for Button onAction
    Sub ExcelImport(control As IRibbonControl)
        Macro4Department (ddIndex)
    End Sub
    
    Sub Macro4Department(i As Long)
        Select Case i
            Case 0
                MsgBox "Department 1 is selected ", vbInformation
            Case 1
                MsgBox "Department 2 is selected ", vbInformation
            Case 2
                MsgBox "Department 3 is selected ", vbInformation
        End Select
    End Sub

    <customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui"><ribbon>
     <tabs>
    <tab id="CustomTab" label="TestLabel">
        <group id="SampleGroup" label="BU Selection">   
            <dropDown id="DdropDown" label="Select Dept" onAction="DReportSelection">
                <item id="item1" label="Depart 1" />
                <item id="item2" label="Depart 2" />
                <item id="item3" label="Depart 3" />
            </dropDown>
         </group >
    
    
        <group id="SampleGroup1" label="TestLabel">
               <button id="Button" label="Import Excel" imageMso="MicrosoftExcel" screentip="Import Data from Excel" size="large" onAction="ExcelImport" />
         </group >
    </tab>
     </tabs>
    </ribbon>
    </customUI>
    Attached Files Attached Files
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

Tags for this Thread

Posting Permissions

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