VBA Checkbox

Hiport

Active Member
Joined
May 9, 2008
Messages
455
Hi, the below code removes the tick from checkbox when workbook opens, how can i add this to a module so i can call this from a module sub rather than Thisworkbook?

ThisWorkbook.Worksheets("Tasks").CheckBox1.Value = False
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Maybe you can try...

Code:
Sub RemoveCheck()
    Worksheets("Tasks").CheckBox1.Value = False
End Sub
 
Upvote 0
Maybe you can try...

Code:
Sub RemoveCheck()
    Worksheets("Tasks").CheckBox1.Value = False
End Sub

Ok i did this and got an error "Method or data member now found CheckBox1

Code:
Sub Test
Dim CheckBox1  As Object
Dim shtTask As Worksheet

Set shtTask = ThisWorkbook.Worksheets("Tasks")
shtTask.CheckBox1.Value = False

End Sub
 
Upvote 0
Are you using a form control or an activeX control - I suggest you use an ActiveX control. dont dim the checkbox - no need
 
Last edited:
Upvote 0
If you are using a form checkbox...

Code:
Sub Test()
    Dim shtTask As Worksheet
    Set shtTask = Worksheets("Tasks")
    shtTask.CheckBoxes("Check box 1").Value = False
End Sub
 
Upvote 0
If you are using a form checkbox...

Code:
Sub Test()
    Dim shtTask As Worksheet
    Set shtTask = Worksheets("Tasks")
    shtTask.CheckBoxes("Check box 1").Value = False
End Sub

I'm am using active x, your code in #2 works, but why doesnt it work for my method of setting worksheet?
 
Upvote 0
As Jeffrey says, the last method he shows is for Forms toolbar checkboxes.

Why not use the codename for the sheet, and get the benefit of IntelliSense?

Code:
Sheet1.CheckBox1.Value = False

Change Sheet1 to the codename for the sheet.
 
Upvote 0
As Jeffrey says, the last method he shows is for Forms toolbar checkboxes.

Why not use the codename for the sheet, and get the benefit of IntelliSense?

Code:
Sheet1.CheckBox1.Value = False
Change Sheet1 to the codename for the sheet.

This Works


Worksheets("Tasks").CheckBox1.Value = False
</pre>
But this does not work


Dim shtTask As Worksheet

Set shtTask = ThisWorkbook.Worksheets("Tasks")
shtTask.CheckBox1.Value = False
</pre>
 
Upvote 0
Right, it doesn't.

Checkbox1 only exists in the context of a particular worksheet. I believe it is the case when you pick an object from the worksheets collection (set wks = worksheets(...)), you create a container that gets searched for the checkbox object at runtime.

When you set a worksheet object variable, that doesn't happen.

That's as well as I can explain it.
 
Upvote 0

Forum statistics

Threads
1,224,564
Messages
6,179,548
Members
452,927
Latest member
rows and columns

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top