I've tried so many variations without success I have lost my brain. I need to set a group of variables based on which option button is selected within it's given group. There are 3 groups simply labeled OptionGroup1, OptionGroup2, & OptionGroup3. When the start button is executed I need to determine which options are selected and set the corresponding variables for use else where in the code. PowerPoint definitely is not the same as excel and I can't seem to get the right syntax for it. This particular attempt gives me "runtime error 438", "the object does not support this property or method"
Set myDocument = ActivePresentation.Slides(1)
Select Case myDocument.Shapes.GroupName = OptionGroup2
Case Is = 1: ACLDelay = 1
Case Is = 2: ACLDelay = 2
Case Is = 3: ACLDelay = 3
Case Is = 4: ACLDelay = Int((4 * Rnd) 1)
End Select
Select Case myDocument.Shapes.GroupName = OptionGroup1
Case Is = 1: RunInt = 15
Case Is = 2: RunInt = 60
Case Is = 3: RunInt = 30
Case Is = 4: RunInt = 5
End Select
Select Case myDocument.Shapes.GroupName = OptionGroup1
Case Is = 1: MODDelay = 1.5
Case Is = 2: MODDelay = 1
Case Is = 3: MODDelay = 2
Case Is = 4: MODDelay = 0.5
End Select
CodePudding user response:
As a starter for 10 you need to reorganise the Select construct for the option groups.
Select Case MyDocument.Shapes.Groupname
Case OptionGroup1
Case optionGroup2
Case OptionGroup3
End Select
The above construct will work if 'MyDocument.Shapes.Groupname, OptionaGroup1,2,3' all yeild strings which can be compared. To workout what happens in each case clause you need to provide the information requested in my comment above. I'll update this answer when you do so.
CodePudding user response:
Please, try the next way. "Opt1", "Opt1" etc. should be the names of the option buttons (you may use their caption, too, but the code must be adapted):
Sub testOptButtGroupName()
Dim ap As Presentation, sh As Shape, opB As MSForms.OptionButton
Dim RunInt As Long, ACLDelay As Long 'you probably have to declare these variable at the module level
Set ap = ActivePresentation
For Each sh In ap.Slides(1).Shapes
If sh.Type = msoOLEControlObject Then
If TypeName(sh.OLEFormat.Object) = "OptionButton" Then
Select Case sh.OLEFormat.Object.GroupName
Case "OptionGroup1"
Select Case sh.Name
Case "Opt1"
If sh.OLEFormat.Object.Value = True Then RunInt = 15
Case "Opt2"
If sh.OLEFormat.Object.Value = True Then RunInt = 60
'and so on...
End Select
Case "OptionGroup2"
Select Case sh.Name
Case "Opt5"
If sh.OLEFormat.Object.Value = True Then ACLDelay = 1
Case "Opt6"
If sh.OLEFormat.Object.Value = True Then ACLDelay = 2
'and so on...
End Select
'and so on...
End Select
End If
End If
Next
Debug.Print RunInt, ACLDelay
End Sub
In fact, using the controls name makes no necessary the use their group membership...
I will leave my office now. If something not clear, do not hesitate to ask for clarifications. I will clarify them when I will be at home.