需要对象

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

我正在尝试在 Word 中创建一个复选框并在单击该复选框时执行功能,但出现“需要对象”的错误。 我将复选框的名称命名为“CheckBox1”,并将宏函数命名为“CheckBox1_Click”。选中复选框后,我想用文本更新表格行。

Public Sub CheckBox1_Click()
On Error GoTo ErrorHandler

Dim tbl As Table
Set tbl = ActiveDocument.Tables(2)

If CheckBox1.Value = True Then
    'Update Table2 Row 7 with ""
    tbl.Cell(7, 1).Range.Text = "input1"
Else
    'Clear the contents of Table2 Row 7
    tbl.Cell(7, 1).Range.Text = ""
End If

Exit Sub

ErrorHandler:
MsgBox "Error: " & Err.Description
End Sub
vba word
© www.soinside.com 2019 - 2024. All rights reserved.