简体   繁体   中英

calling a sub function with a button in vba

I have 10 Sub function macros in "This workbook". Instead of running each macros, everytime i wanted an userform with button, and when I click , it should execute all the Sub function in "This workbook".

Sub calling()


Call lookup
Call RangeTest
 Call datecompare
Call AutoPivot
Call Autochart
 Call pivot
Call chart
Call pivot1
End Sub

You should simply add a button from the developper ribbon and assign it to calling(). However, make sure all your macros are in the same module or else you'll have to specify it. If you still get an error it would be interesting to see on what line the error is coming from.

Thank you

I'm assuming the confusion arises because you are trying to use an ActiveX button. If you were using a Form Button, the macro name would appear in the "Assign Macro" popup box. But the ActiveX version doesn't provide the dialog, and because the button exists on the page, doesn't easily see the macros from "This Workbook".

Here's what worked for me.

Within Sheet3:

Private Sub CommandButton1_Click()
    Application.Run ("'ThisWorkbook.calling'")
End Sub

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM