PDA

View Full Version : [SOLVED:] Passing a Registry Key Value to a dropdown box



Roderick
10-01-2017, 06:07 AM
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?

SamT
10-01-2017, 07:41 AM
DropdownBox = StringVariable

gmaxey
10-01-2017, 08:11 AM
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>

Roderick
10-02-2017, 01:52 PM
Thank you, Greg.

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

Paul_Hossler
10-06-2017, 07:11 AM
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




20589



I couldn't get the XML to display correctly, so attaching my test docm

Roderick
10-12-2017, 07:49 AM
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?

Paul_Hossler
10-12-2017, 08:14 AM
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