When a user runs a GUI on a PPT slide it brings up a userform, pictured below.

They can select up to 3 hazards in the check boxes. I am trying to find a way to loop through all the check boxes to see which ones are selected (if none, then it will just exit the sub). Then, based on which one(s) is(are) selected, it will enter a corresponding image into a shape within the PPT slide. The shapes are lined up from left to right. The "highest ranking" selection would go in the left shape, with the "lowest ranking" of the three going in the right box. Only the first and second shapes would be filled if there are only two options selected. I am not sure the easiest way to assign values (i.e. 1, 2, 3, etc) to the order of importance for each option. I would prefer not to have to cover every combination with If -> Then statements as that would be tedious and quite time consuming. I assume there is a better way to do this?
I am able to loop through the combobox lists easily by using the following code:
Private Sub MainImage()
Call Dictionary.MainImageDict
'References the Dictionary for the Main Image options.
ComboBoxList = Array(CStr(ComboBox2)) 'ComboBox2 is the Main Image dropdown.
For Each Ky In ComboBoxList
On Error Resume Next
'If nothing is selected in the Main Image dropdown, do nothing and exit this sub.
If Ky = "" Then
Exit Sub
'Otherwise, if anything is selected in the Main Image dropdown, insert image and remove placeholder text.
ElseIf Ky <> "" Then
ActiveWindow.Selection.SlideRange.Shapes("MainImage").Fill.UserPicture (dict3.Item(Ky)(0))
End If
Next
Set dict3 = Nothing
End Sub
The dictionary referenced above is as follows:
Public dict, dict2, dict3, dict4, dict5 As Object, Key, val 'Makes the dictionaries public so they can be accessed by other Modules.
Sub MainImageDict()
'This is the dictionary for the Main Image portion of the slides.
Set dict3 = CreateObject("Scripting.Dictionary")
Key = "Day 1 High Temperatures": val = Array("URL_to_Image")
dict3.Add Key, val
Key = "Day 2 High Temperatures": val = Array("URL_to_Image")
dict3.Add Key, val
End Sub
I would like to do something similar, if possible, with the check boxes. Since they are all separate, and not combined into one (like the combobox), I am not sure how to go about doing this. Any help would be greatly appreciated! Please let me know if anything I said does not make sense. Thank you!
UPDATED CODE
Using the suggested code works wonderfully. Now I have one final question. I have modified the code to the following:
Private Sub Hazards()
Call Dictionary.HazardsDict
'References the Dictionary for the Hazard Image options.
Dim chkboxes As Variant
Dim iCtrl As Long
Select Case CountSelectedCheckBoxes(chkboxes)
Case Is > 3
MsgBox "Too many selected checkboxes!" & vbCrLf & vbCrLf & "please select three checkboxes only!", vbCritical
Case Is = 1 'If only one checkbox is selected
For iCtrl = LBound(chkboxes) To UBound(chkboxes)
HazardList = Array(chkboxes(iCtrl).Caption)
Debug.Print chkboxes(iCtrl).Caption
Next
'MsgBox chkboxes(iCtrl).Tag '<--| here you output each selected checkbox Tag. you can use this "number"
For Each Ky In HazardList
ActiveWindow.Selection.SlideRange.Shapes("Hazard1").Fill.UserPicture (dict5.Item(Ky)(0))
ActiveWindow.Selection.SlideRange.Shapes("Hazard1Text").TextFrame.TextRange.Text = dict5.Item(Ky)(1)
Next
Case Is = 2 'If exactly 2 checkboxes are selected
For iCtrl = LBound(chkboxes) To UBound(chkboxes)
HazardList = Array(chkboxes(iCtrl).Caption)
Debug.Print chkboxes(iCtrl).Caption
Next
For Each Ky In HazardList
ActiveWindow.Selection.SlideRange.Shapes("Hazard1").Fill.UserPicture (dict5.Item(Ky)(0)) 'The checkbox with the lowest number in its Tag would go here.
ActiveWindow.Selection.SlideRange.Shapes("Hazard1Text").TextFrame.TextRange.Text = dict5.Item(Ky)(1)
ActiveWindow.Selection.SlideRange.Shapes("Hazard2").Fill.UserPicture (dict5.Item(Ky)(0)) 'The checkbox with the second lowest tag number would go here
ActiveWindow.Selection.SlideRange.Shapes("Hazard2Text").TextFrame.TextRange.Text = dict5.Item(Ky)(1)
Next
End Select
Set dict5 = Nothing
End Sub
I am trying to figure out how I would write the code so that the checkbox with the lowest number in its Tag goes into "Hazard1", the Tag with the second lowest number (of the up to 3 that can be selected) goes into Hazard2, and the Tag with the third lowest number goes into Hazard3. Any ideas? Thank you!