[英]How to call DblClick sub from code VBA Excel
I have an Excel worksheet with two forms: Form1
and Form2
. 我有一个具有两种形式的Excel工作表:
Form1
和Form2
。
Form1
has TextBox1 with double-click events: Form1
TextBox1具有双击事件:
Public Sub TextBox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
' Some activity...
End Sub
Form2
has CommandButton2
with a click event: Form2
具有带有click事件的CommandButton2
:
Private Sub CommandButton2_Click()
' Another activity...
End Sub
I need to call the TextBox1_DblClick
sub from the CommandButton2_Click
sub. 我需要从
CommandButton2_Click
子调用TextBox1_DblClick
子。
How can I make a call like this? 我该如何拨打电话?
Create a new module , add to it the sub with the operations you wish to perform 创建一个新模块 ,在其中添加您要执行的操作的子模块
Sub mySubroutine()
' Do stuff
End Sub
Then call this from both of your click handlers 然后从两个点击处理程序中调用
' In Form1
Public Sub TextBox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
mySubroutine
End Sub
' In Form2
Private Sub CommandButton2_Click()
mySubroutine
End Sub
If you wanted to pass stuff (like text box strings etc) from your forms, then include input arguments in your sub 如果您想从表单中传递内容(例如文本框字符串等),则在子控件中包含输入参数
Sub mySubroutine(str As String, n As Long) ' Passing arguments
' Do stuff
End Sub
Then pass those arguments when you make the call from anywhere 当您从任何地方拨打电话时,然后传递这些参数
' Get a String and Long from data on the form, then call mySubroutine
mySubroutine str:=myString, n:=myLong
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.