[英]VBA have a sub run another sub
how to run a sub
stored in another worksheet's module?如何运行存储在另一个工作表模块中的
sub
?
worksheet1工作表1
sub endDay()
'something here
end sub
worksheet2工作表2
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.我希望
recalc
能够自己运行,但我希望能够按下“endDay”的按钮,让它做它的事情,然后在最后预制“recalc”而不是按下一个然后转到 sheet2按另一个。
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.查看工作表的代码名称 - 您可以在 Visual Basic 编辑器的树视图中看到它们。 Usually they are named
Sheet1
, Sheet2
, etc. (independent of the actual worksheet names, which are shown in brackets).通常它们被命名为
Sheet1
、 Sheet2
等(独立于实际工作表名称,显示在括号中)。 Use this name in your code )instead of Worksheets("Sheet1")
and you'll also get an autocomplete list - with your sub!在您的代码中使用此名称) 而不是
Worksheets("Sheet1")
,您还将获得一个自动完成列表 - 与您的子!
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.我知道是 2 年后,但今天我正在寻找同样的东西。 As far as the subs in the worksheets may be private, this is a good solution:
至于工作表中的 subs 可能是私有的,这是一个很好的解决方案:
Sub Maina()
Run "tbl_Input.btn_main_Click"
End Sub
tbl_Input
is the VBA name of the worksheet, not the caption. tbl_Input
是工作表的 VBA 名称,而不是标题。
Call Module1.reCalc
should work as well if the Sub is in Module1.如果 Sub 位于 Module1 中,则
Call Module1.reCalc
应该也能正常工作。 It may be unnecessary to have 'Module1.'可能没有必要拥有“模块 1”。 at all though.
尽管如此。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.