ユーザーがPPTスライドでGUIを実行すると、以下のようなユーザーフォームが表示されます。 VBoxを使用したPowerpointのユーザーフォームのチェックボックスループ
これらのチェックボックスでは、最大3つのハザードを選択できます。どのチェックボックスが選択されているかを確認するために、すべてのチェックボックスをループする方法を見つけようとしています(どれも選択されていない場合は、サブを終了します)。次に、どちらが選択されているかに基づいて、対応するイメージをPPTスライド内の図形に入力します。形状は左から右に並んでいます。 「最も高いランク付け」の選択は左の形になり、3つの「最も低いランク付け」が右側のボックスに入ります。オプションが2つしか選択されていない場合、第1および第2の形状のみが充填される。私は、各オプションの重要度の順序に値(1,2,3など)を割り当てる最も簡単な方法がわかりません。私は、If - > Thenステートメントですべての組み合わせをカバーする必要がない方が好きです。というのも、面倒で時間がかかるからです。私はこれを行うより良い方法があると思いますか?
私は次のコードを使用して簡単にコンボボックスのリストをループできる午前:
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
次のように上に参照辞書は次のとおりです。
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
私は似た何かをしたいと思い、可能であれば、チェックボックスをオンにします。彼らはすべて別々であり、コンボボックスのように1つに結合されているわけではないので、私はこれをどうやって行うのかについてはわかりません。どんな助けでも大歓迎です!私が言ったことが意味をなさないと言ったら教えてください。ありがとうございました!
提案コードを使用して更新されたコードは
素晴らしく動作します。今私は1つの最終的な質問があります。
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
私はそのタグで最も小さい番号のチェックボックスが第二に、「Hazard1」、にタグを行くように、私はコードを書くだろうか把握しようとしています:私は、次のようにコードを変更しました最も低い番号(選択可能な3つまで)がHazard2に入り、3番目に小さい番号のタグがHazard3に入ります。何か案は?ありがとうございました!
それは完全に動作します。ありがとうございました!私は最後の質問が1つあります。私は元の質問を修正しました。あなたは修正されたコードと私の質問を下に向かって見ることができます。再度、感謝します! – hunter21188
ようこそ。解決策を受け取った後で質問を変更すると、ここで許可されていない "シャンレオン"の質問につながることにご注意ください。だから、私の答えがあなたの_original_質問を解決したら、それを受け入れたものとしてマークしてください。 _new_号に_new_投稿を作成したい場合があります。ありがとうございました – user3598756