我嘗試了很多變體都沒有成功,我已經失去了理智。我需要根據在給定組中選擇的選項按鈕來設定一組變數。有 3 個組,簡單地標記為 OptionGroup1、OptionGroup2 和 OptionGroup3。當執行開始按鈕時,我需要確定選擇了哪些選項并設定相應的變數以在代碼中的其他位置使用。PowerPoint 絕對與 excel 不同,我似乎無法獲得正確的語法。這個特殊的嘗試給了我“運行時錯誤 438”,“物件不支持這個屬性或方法”
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
uj5u.com熱心網友回復:
作為 10 的初學者,您需要重新組織選項組的 Select 構造。
Select Case MyDocument.Shapes.Groupname
Case OptionGroup1
Case optionGroup2
Case OptionGroup3
End Select
如果 'MyDocument.Shapes.Groupname, OptionaGroup1,2,3' 所有 yeild 字串都可以進行比較,則上述構造將起作用。要計算每個 case 子句中發生的情況,您需要提供我上面評論中要求的資訊。當你這樣做時,我會更新這個答案。
uj5u.com熱心網友回復:
請嘗試下一個方法。“Opt1”、“Opt1”等應該是選項按鈕的名稱(您也可以使用它們的標題,但必須修改代碼):
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
事實上,使用控制元件名稱不需要使用它們的組成員身份......
我現在要離開我的辦公室。如果有不清楚的地方,請不要猶豫,要求澄清。當我在家時,我會澄清它們。
uj5u.com熱心網友回復:
我使用簡單的 IF 陳述句來解決我的問題。這不是最有效的方法,但目前有效。
If OptionButtonACL1s.Value = True Then
ACLDelay = 1
End If
If OptionButtonACL2s.Value = True Then
ACLDelay = 2
End If
If OptionButtonACL3s.Value = True Then
ACLDelay = 3
End If
If OptionButtonACLr.Value = True Then
ACLDelay = Int((10 * Rnd) 1)
End If
If OptionButtonMOD5s.Value = True Then
MODDelay = 0.5
End If
If OptionButtonMOD1s.Value = True Then
MODDelay = 1
End If
If OptionButtonMOD15.Value = True Then
MODDelay = 1.5
End If
If OptionButtonMOD2s.Value = True Then
MODDelay = 2
End If
If OptionButtonRT5m.Value = True Then
RunInt = 5
End If
If OptionButtonRT15m.Value = True Then
RunInt = 15
End If
If OptionButtonRT30m.Value = True Then
RunInt = 30
End If
If OptionButtonRT1h.Value = True Then
RunInt = 60
End If
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/366926.html
上一篇:選擇圖表時呼叫宏
下一篇:為什么我的函式不回傳新字串?
