CommandButton properties in Excel

CommandButton properties in Excel

Anonymous
Not applicable
465 Views
3 Replies
Message 1 of 4

CommandButton properties in Excel

Anonymous
Not applicable
Hello!
I am working on a VB project for AutoCAD Electrical where I need to read the 'caption' of a commandbutton located on an excel worksheet. I know how to access the data from the spread sheet using the workbook objects but I am at a loss here regarding the commandbutton object & its properties. If I was writing an excel macro, this is how I would use it:

If ActiveSheet.Shapes("cmdHide").Caption = "UNHIDE" Then
ActiveSheet.Shapes("cmdHide").Select
End If

I have tried defining worksheet shapes object & also use the dropdown property but it just doesn't work. Any advice please?
Thanks in advance.
0 Likes
466 Views
3 Replies
Replies (3)
Message 2 of 4

Anonymous
Not applicable
Assuming the button is named "cmdHide", you can read / set the caption as
shown below.

Gary

MsgBox "Button caption is: " & ActiveSheet.cmdHide.Caption

If ActiveSheet.cmdHide.Caption = "UN-HIDE" Then
ActiveSheet.cmdHide.Caption = "HIDE"
Else
ActiveSheet.cmdHide.Caption = "UN-HIDE"
End If
0 Likes
Message 3 of 4

Anonymous
Not applicable
Thanks a lot Gary! I don't know why it did not occur to me. It seems so simple. Anyways, this is what I am using right now (in Autocad VB):

If ActiveSheet.cmdHide.Caption = "UNHIDE" Then
ActiveSheet.cmdHide.Select
End If

The new issue is, when the code sees the UNHIDE caption for the commandbutton ("cmdHide") in excel, it should click that button. I thought 'Select' would work but it looks like I need a new function for 'click' events.
I have searched other threads but they talk about the command button within autocad userforms. The commandbutton I need to click is external to acad (in excel). Is it possible to click it from acad VB environment?
Thanks again.
0 Likes
Message 4 of 4

Anonymous
Not applicable
If you know you want to unconditionally run a block of code based on what
the button caption is, why not just run it? Why do you want, or need, to
select the button?

Gary
0 Likes