Consulting

Results 1 to 3 of 3

Thread: How to call DblClick sub from code VBA Excel

  1. #1
    VBAX Regular
    Joined
    Jul 2017
    Posts
    6
    Location

    How to call DblClick sub from code VBA Excel

    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?

  2. #2
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    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
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  3. #3
    VBAX Regular
    Joined
    Jul 2017
    Posts
    6
    Location
    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.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •