Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How can I call a module written in Excel by clicking on an ActiveX control in a worksheet?

share|improve this question

It's not entirely clear what you're asking, but I understand this to be your problem:

You have an ActiveX Control that runs on a click event. The VBA for this is only called by the button click and cannot be called from any other Sub, but you would like to be able to call this code from another module.

I don't believe you can do that, but there is a better approach to the problem. Place the code for your ActiveX control in a new Sub in a module. Then replace the code for the button click event with the following:

Private Sub CommandButton1_Click()
Call NewSub
End Sub

Where NewSub is the name of your new Sub. This should allow you to do what you wanted.

share|improve this answer

The code for an ActiveX control, such as a button_click on a worksheet, may be called from other subs, even on other modules. Simply use the keyword "Public" to describe the ActiveX control sub instead of "Private". Then call the sub with a statement such as Call Sheets(mySheetName).myButtonName_Click.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .