사용자가 PPT 슬라이드에서 GUI를 실행하면 사용자 폼이 표시됩니다 (아래 그림 참조).PowerPoint VBA의 배열에서 가장 낮은 값, 두 번째 가장 낮은 값 및 가장 높은 값 찾기
그들은 확인란 3 개 위험까지 선택할 수 있습니다. 나는 그 코드에서 가장 낮은 숫자의 체크 박스가 "Hazard1"에 들어가도록 코드를 작성하는 방법을 알아 내려고 노력하고 있는데, 두 번째로 낮은 숫자 (선택 가능한 3 개까지)의 태그가 Hazard2에 들어간다. 세 번째로 낮은 번호의 태그는 Hazard3으로 이동합니다. 모든 체크 박스의 각 Tag 속성에는 하나의 숫자 만 있습니다. 이것이 내 순위 우선 순위에 사용할 것입니다.
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
Function CountSelectedCheckBoxes(chkboxes As Variant) As Long
Dim ctrl As Control
ReDim chkboxes(1 To Me.Controls.count)
For Each ctrl In Me.Controls '<--| loop through userform controls
If TypeName(ctrl) = "CheckBox" Then '<--| check if current control is a "checkbox" one
If ctrl Then '<--| check if it's "checked"
CountSelectedCheckBoxes = CountSelectedCheckBoxes + 1 '<--| update checked checkboxes counter
Set chkboxes(CountSelectedCheckBoxes) = ctrl '<--| store it in the array
End If
End If
Next
If CountSelectedCheckBoxes > 0 Then ReDim Preserve chkboxes(1 To CountSelectedCheckBoxes) '<--|size checkboxes array to actual checked checkboxes found
End Function
어떤 아이디어 :
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. This is the "number" to use in the ranking
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
위의 코드는 다음과에이 참조하는 사전 : 여기
지금까지 코드? 고맙습니다!
체크 박스 개체를 감지 할 수 있도록 'CountSelectedCheckBoxes'에 대한 코드를 표시 할 수 있습니까? –
죄송합니다, 나는 그것을 포함하고자했습니다! 게시물을 업데이트했습니다. – hunter21188
파일을 업로드해야 할 필요가 있다고 생각합니다. 문제 해결을 위해 너무 많은 일이 여기에 있습니다. – brettdj