在 Word 中使用复选框形状时出现编译错误 (VBA)

Getting compile error using checkbox shapes in Word (VBA)

我在尝试检查表单上的形状是否为复选框时收到“编译错误:未找到方法或数据成员”。这是我正在使用的代码:

For Each cb In ActiveDocument.Shapes
If cb.Type = msoFormControl Then
  If cb.FormControlType = xlCheckBox Then
    If cb.ControlFormat.Value = xlOn Then
    Next cb
    strFile = Dir(strFolder & cb.Text, vbNormal)
If Dir(strFolder & cb.Text) = "" Then
    MsgBox "The file '" & checkbox.Caption & "' does not exist in the specified folder. Please try again."
    Exit Sub
End If [...]

它特别突出了错误中的第二行FormControlType。有没有我应该引用的图书馆?

您是说复选框在用户表单上吗?如果是这样,您需要遍历表单上的控件并检查每个控件的类型名称(即“CheckBox”)。

例如:

Dim ctrl As control

For Each ctrl In Me.Controls
    If TypeName(ctrl) = "CheckBox" Then

等等……

这个有效:

  Dim ctrl As ContentControl
  For Each ctrl In ActiveDocument.ContentControls
    If ctrl.Type = wdContentControlCheckBox Then
        If ctrl.Checked = True Then