PDA

View Full Version : [SOLVED] How to call DblClick sub from code VBA Excel



Juraj
07-25-2017, 09:06 AM
I have an Excel worksheet with two forms Form1 and Form2. Form1 has TextBox1 with DoubleClick event:

Public Sub TextBox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
' Some activity...
End Sub

Form2 has CommandButton2 with Click event:

Private Sub CommandButton2_Click()
' Another activity...
End Sub

I need call TextBox1_DblClick Sub from CommandButton2_Click Sub. What are exact code and parameter type for this calling?

mdmackillop
07-25-2017, 09:56 AM
I would put the action in a separate module


'Module 1
Sub Test(Data As String)
MsgBox Data
End Sub


'Userform1
Private Sub TextBox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
Call Module1.Test(TextBox1)
UserForm2.Show
End Sub


'Userform2
Private Sub CommandButton2_Click()
Call Module1.Test(UserForm1.TextBox1)
End Sub

Juraj
07-26-2017, 01:18 AM
Thank you for your answer. I had problems with straight calling the TextBox1_DblClick. I solved it by extracting some code - which I needed to execute - from TextBox1_DblClick procedure, putting it into a new procedure without parameters and calling this new procedure. Not straightforward solution but works.