Share via

disable an activex button in VBA code

Anonymous
2011-12-17T02:58:59+00:00

I have a few activex buttons on a worksheet, I want to disable one named butInsertRow on certain conditions. What is the VBA code for this?

Thanks

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Anonymous
2011-12-17T11:37:35+00:00

Build the disable mechanism into the button code.  For example, for a button named buttton code like:

Private Sub buttton_Click()

If StopMe Then

    Exit Sub

End If

MsgBox "Good Morning Louise"

End Sub

and in a standard module:

Public StopMe As Boolean

Sub MAIN()

StopMe = False

'  do more stuff

End Sub

Sub routine()

' disable the button code

StopMe = True

End Sub

Running MAIN enables the button logic and running routine disables it.

The advantage to this approach is that the user can see the state of the button by examining the Boolean.

Was this answer helpful?

0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Anonymous
    2011-12-17T11:27:32+00:00

    Try code like

    ThisWorkbook.Worksheets("Sheet1"). _

        OLEObjects("butInsertRow").Enabled = False

    Was this answer helpful?

    0 comments No comments