简体   繁体   English

引用另一个打开的工作簿中的复选框

[英]Reference a check box in another open workbook

I am trying to refer to the value of an ActiveX checkbox control in another worksheet. 我试图在另一个工作表中引用ActiveX复选框控件的值。 My goal is to make the value of the check box in my current workbook the same as the one in another open workbook. 我的目标是使当前工作簿中的复选框的值与另一打开的工作簿中的复选框的值相同。

I can do this between two checkboxes in the same workbook on different sheets: 我可以在同一工作簿中不同工作表的两个复选框之间执行此操作:

Private Sub CommandButton1_Click()

If Sheets("Sheet2").Box2.Value = True Then
    Box1.Value = True
Else: Box1.Value = False
End If

End Sub

But I'm receiving a Run-time error '9' "Subscript out of range" error when I run the following code: 但是,当我运行以下代码时,我收到运行时错误“ 9”“下标超出范围”错误:

Private Sub CommandButton2_Click()

If Worksheets("Book2").OLEObjects("Box3").Value = True Then
    Box1.Value = True
Else: Box1.Value = False
End If

End Sub 结束子

The "If Worksheets" line is highlighted when I try to debug the code. 当我尝试调试代码时,“ If Worksheets”行会突出显示。 I'm sure I'm referring to the other checkbox incorrectly, but I've searched high and low for the proper way to refer to this without any luck. 我确定我在错误地引用了另一个复选框,但是我一直在寻找适当的方式来引用它,而没有运气。 Thank you in advance for your help! 预先感谢您的帮助!

If Worksheets("Book2").OLEObjects("Box3").Value = True Then

"Book2" is not the name of a Worksheet, presumably it is the name of the other book. “ Book2”不是工作表的名称,大概是另一本书的名称。 In which case: 在这种情况下:

If WorkBooks("Book2").Worksheets(1).OLEObjects("Box3").Value = True Then

..or use whatever the name of the worksheet in the other book is called. ..或使用另一本书中称为工作表的名称。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM