简体   繁体   English

如何将VB复选框的值传递给Excel复选框

[英]How to pass value of vb checkbox to excel checkbox

I've tried the things here on the internet but I still can't make it work. 我已经在互联网上尝试过这些东西,但仍然无法正常工作。

My code is like this: 我的代码是这样的:

Dim oXL As Excel.Application
Dim oWB As Excel.Workbook
Dim oSheet As Excel.Worksheet
Dim oRng As Excel.Range

If Center_for_Patient_PartnershipsCboxCheckBox.CheckState = CheckState.Checked Then
    oSheet.OLEObjects("Check Box 1").Object.Value = 1
Else
    oSheet.OLEObjects("Check Box 1").Object.Value = 0
End If`

If it's a Form Control check box: 如果是“表单控件”复选框:

oSheet.Shapes("Check box 1").ControlFormat.Value = 0  'Uncheck
oSheet.Shapes("Check box 1").ControlFormat.Value = 1  'Check

If it's an Active X check box: 如果是Active X复选框:

oSheet.OLEObjects("CheckBox1").Object.Value = 0  'Uncheck
oSheet.OLEObjects("CheckBox1").Object.Value = 1  'Check

Notice that the name of the active x control can't have spaces but the form control check box can. 请注意,活动x控件的名称不能有空格,但窗体控件复选框可以。 This is why I provided both answers. 这就是为什么我提供了两个答案的原因。

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

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