how to run a sub
stored in another worksheet's module?
worksheet1
sub endDay()
'something here
end sub
worksheet2
sub reCalc()
'something here
end sub
I want recalc
to be able to run on its own but I want to be able to press the button for "endDay", have it do its thing, and then preform "recalc" at the end instead of pressing one and then go to sheet2 to press the other.
Can someone give me a sample so I can have an idea where to begin?
Take a look at the code names for the worksheets - you can see them in the tree view in the Visual Basic Editor. Usually they are named Sheet1
, Sheet2
, etc. (independent of the actual worksheet names, which are shown in brackets). Use this name in your code )instead of Worksheets("Sheet1")
and you'll also get an autocomplete list - with your sub!
Thus, this will do the job:
Sheet1.reCalc
sheets("worksheet2").reCalc
可能是你所追求的
I know it is 2 years later, but today I was looking for the same thing. As far as the subs in the worksheets may be private, this is a good solution:
Sub Maina()
Run "tbl_Input.btn_main_Click"
End Sub
tbl_Input
is the VBA name of the worksheet, not the caption.
Call Module1.reCalc
should work as well if the Sub is in Module1. It may be unnecessary to have 'Module1.' at all though.
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.