Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

share|improve this question
add comment

2 Answers

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
add comment

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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.