Word VBA 中使用的选项按钮

问题描述 投票:0回答:1

我还有一个问题无法解决。这次指的是选项按钮。

我有一组两个按钮(是和否),还有三组,每组一个按钮。这个想法是,如果没有按钮“打开”,则所有树组都应具有属性“启用”值“假”。基本上,他们应该被阻止。 如果“YES”按钮“打开”,则所有树组都应具有属性“Enabled”值“true”。所有树组都应该“打开”或“关闭”,具体取决于我是否单击它们以及单击它们的次数。这三个按钮是独立的,可以相互组合“开”或“关”。

我尝试使用代码:

Private Sub V1028_Click()
    Dim E As Shape
        If ActiveDocument.Shapes(91) = True Then
            Set E = ActiveDocument.Shapes(96)
            E.Visible = True
            Set E = ActiveDocument.Shapes(97)
            E.Visible = True
            Set E = ActiveDocument.Shapes(98)
            E.Visible = True
        End If
End Sub

我收到信息“对象不支持此属性或方法”!

有人可以帮助我吗? 预先感谢!

vba ms-word
1个回答
0
投票

All three groups should be "on" or "off" depending on whether I click on them and how many times

  • 使用
    CheckBox
    代替
    OptionButton
  • 假设第一个 ActiveX 控件名为
    OptionButton1
Option Explicit
' OptionButton1 change event code
Private Sub OptionButton1_Change()
    Dim ctl As InlineShape
    Dim i As Long, ctlName As Long, opVal As Boolean
    Const CTL_NAME = "CheckBox"
    For Each ctl In ActiveDocument.InlineShapes
        If ctl.OLEFormat.Object.Name = "OptionButton1" Then
            opVal = ctl.OLEFormat.Object.Value
            Exit For
        End If
    Next
    For Each ctl In ActiveDocument.InlineShapes
        Debug.Print ctl.OLEFormat.Object.Name
        If ctl.Type = wdInlineShapeOLEControlObject Then
            If TypeName(ctl.OLEFormat.Object) = "CheckBox" Then
                ctl.OLEFormat.Object.Object.Enabled = opVal
            End If
        End If
    Next
End Sub

© www.soinside.com 2019 - 2024. All rights reserved.