Consulting

Results 1 to 7 of 7

Thread: Passing a Registry Key Value to a dropdown box

  1. #1

    Passing a Registry Key Value to a dropdown box

    I'm using Word 2013 and Word 2016.

    I have a dropdown list in the Ribbon Bar with four items: apples, pears, bananas and kiwi.

    When I select one of those items in the dropdown it opens a userform to ask me what I want to do with that particular fruit:eat it, put in a fruit salad and so on.

    Also, having previously selected a fruit from the dropdown, it passes its value to the Registry for future reference as to what had been chosen.

    I presently use the GetSetting to put the value from the Registry into a string variable but then get stuck as to what to do next to nudge it on its way.

    What I want to do now is to get that Registry value and pass it back to the dropdown so that it makes a constant display of what fruit was earlier selected every time I run the template.

    Is this possible, please?

  2. #2
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    DropdownBox = StringVariable
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  3. #3
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,334
    Location
    The RibbonX


    The code:

    Option Explicit
    Private oRibbon As IRibbonUI
    Sub Onload(ribbon As IRibbonUI)
    'Create a ribbon instance for use in this project
      Set oRibbon = ribbon
    lbl_Exit:
      Exit Sub
    End Sub
    Sub myDDMacro(ByVal control As IRibbonControl, selectedID As String, _
                   selectedIndex As Integer)
      MsgBox "What do you want to do with " & Choose(selectedIndex + 1, "Apples", "Bananas", "Kiwis", "Pears")
      SaveSetting "Ribbon DD Demo", "Settings", "Index", CStr(selectedIndex)
    lbl_Exit:
      Exit Sub
    End Sub
    Sub GetSelectedItemIndex(ByVal control As IRibbonControl, ByRef Index)
    'This procedure is used to select the last selected index.
    Select Case control.ID
      Case Is = "DD1"
        Index = CLng(GetSetting("Ribbon DD Demo", "Settings", "Index"))
      Case Else
    End Select
    lbl_Exit:
      Exit Sub
    End Sub
    <?xml version="1.0"encoding="UTF-8"standalone="yes"?>
    <customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui"onLoad="RibbonControl.Onload">
    <ribbon>
    <tabs>
    <tab id="CustomTab1"label="My Tab">
    <group id="CustGrp1"label="My Group" >
    <dropDown id="DD1"label="My DD"getSelectedItemIndex="RibbonControl.GetSelectedItemIndex"
    onAction="RibbonControl.MyDDMacro">
    <item id="a"label="Apples"/>
    <item id="b"label="Bananas"/>
    <item id="k"label="Kiwis"/>
    <item id="p"label="Pears"/>
    </dropDown>
    </group>
    </tab>
    </tabs>
    </ribbon>
    </customUI>
    Greg

    Visit my website: http://gregmaxey.com

  4. #4
    Thank you, Greg.

    Will try this in a while and hopefully, report back with success.

  5. #5
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,711
    Location
    Added a 'First Run' check, and some tweaks to Greg's Fluent (mostly to add back spaces that got dropped with posting)


    Option Explicit
    Private oRibbon As IRibbonUI
    Sub Onload(ribbon As IRibbonUI)
         'Create a ribbon instance for use in this project
        Set oRibbon = ribbon
    lbl_Exit:
        Exit Sub
    End Sub
    
    Sub MyDDMacro(ByVal control As IRibbonControl, selectedID As String, _
        selectedIndex As Integer)
        MsgBox "What do you want to do with " & Choose(selectedIndex + 1, "Apples", "Bananas", "Kiwis", "Pears")
        SaveSetting "Ribbon DD Demo", "Settings", "Index", CStr(selectedIndex)
    lbl_Exit:
        Exit Sub
    End Sub
    
    Sub GetSelectedItemIndex(ByVal control As IRibbonControl, ByRef index)
        If Len(GetSetting("Ribbon DD Demo", "Settings", "Index")) = 0 Then
            index = 0
         
         Else
             'This procedure is used to select the last selected index.
        
            Select Case control.id
            Case Is = "DD1"
                index = CLng(GetSetting("Ribbon DD Demo", "Settings", "Index"))
            Case Else
            End Select
        End If
    lbl_Exit:
        Exit Sub
    End Sub

    Capture.JPG



    I couldn't get the XML to display correctly, so attaching my test docm
    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

  6. #6
    Thanks all. The client wants a button rather than a dropdown so the problem is solved. The button on the Ribbon Bar works a treat!

    By the way, how can I make an entry that says the problem is Solved to a query?

  7. #7
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,711
    Location
    Quote Originally Posted by Roderick View Post
    Thanks all. The client wants a button rather than a dropdown so the problem is solved. The button on the Ribbon Bar works a treat!

    By the way, how can I make an entry that says the problem is Solved to a query?

    3. in my sig
    ---------------------------------------------------------------------------------------------------------------------

    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

Posting Permissions

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