how to check if a checkbox is checked or not

I'm trying to add in a "save username and password" checkbox on my excel sheet, but can't seem to call it from the code. I can't find how to reference it from the code, so I can see if it's checked or not.

I tried:

chbxSaveUNPW.checked = false
chbxSaveUNPW.value = 0
sheet2.chbxSaveUNPW.value = 0

The code doesn't recognize my checkbox. =( How do I reference an object on a sheet? I don't want to run a macro when it's clicked, just want to see if it's checked or not.

Comments

  • : I'm trying to add in a "save username and password" checkbox on my excel sheet, but can't seem to call it from the code. I can't find how to reference it from the code, so I can see if it's checked or not.
    :
    : I tried:
    :
    : chbxSaveUNPW.checked = false
    : chbxSaveUNPW.value = 0
    : sheet2.chbxSaveUNPW.value = 0
    :
    : The code doesn't recognize my checkbox. =( How do I reference an object on a sheet? I don't want to run a macro when it's clicked, just want to see if it's checked or not.
    :
    Hi,
    if you've place checkbox on your sheet, excel creates the instance of it. I suppose you've rename it to cbxSaveUNPW..
    When you're accessing the checkbox from outside codebehind of your sheet (let's say sheet2), you have to use whole name like sheet2.chbxSaveUNPW..
    so your code looks all right..
    Try to take a look at the name of the check box (I would use cbxSaveUNPW instead of chbxSaveUNPW...). And when you're starting to write the name, VBA intellisence will offer you your check box, so if it does not, there's mistake in the name of it..

    When you're checking if checkbox is checked in VBA, use .Value (boolen).
    Try
    MsgBox Sheet2.chbxSaveUNPW.Value
    for debug..

    Hope this helps.

    [blue][b][italic][size=4]P[/size]avlin [size=4]II[/italic][/size][/b][/blue]

    [purple]Don't take life too seriously anyway you won't escape alive from it![/purple]


  • That didn't work.

    When I type 'sheet2', I don't find my checkbox in the list. I tried to locate it in the object browser, but I can't even find it there.
  • : That didn't work.
    :
    : When I type 'sheet2', I don't find my checkbox in the list. I tried to locate it in the object browser, but I can't even find it there.
    :
    Hmmm..
    it looks like some deeper excel problem.. What version of it are you using? (Check, if macros are enabled in your app but I suppose they are..)



    [blue][b][italic][size=4]P[/size]avlin [size=4]II[/italic][/size][/b][/blue]

    [purple]Don't take life too seriously anyway you won't escape alive from it![/purple]


Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories