Forum

VBA code to require...
 
Notifications
Clear all

VBA code to require double click to run macro assigned to button

3 Posts
3 Users
0 Reactions
120 Views
(@tkerrinstallnet-com)
Posts: 1
New Member
Topic starter
 

Does anyone know the code necessary to make double clicking a button with a macro assigned the default behavior?  I thought Copilot would lead me to the answer but, alas, it did not.

 
Posted : 10/04/2025 4:43 am
Anders Sehlstedt
(@sehlsan)
Posts: 966
Prominent Member
 

Hello,

I have not checked if it works as intended, but this is the reply from Copilot.

Dim LastClickTime As Double

Private Sub CommandButton1_Click()
If Timer - LastClickTime < 0.5 Then
' Run your macro here
MsgBox "Macro executed!"
Else
MsgBox "Please double-click the button."
End If
LastClickTime = Timer
End Sub

 
Posted : 10/04/2025 6:43 am
(@vandaloit)
Posts: 1
New Member
 

if it is a shape in a worksheet try this

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
    Dim Shp As Shape
    For Each Shp In ActiveSheet.Shapes
        If Not Intersect(Target, Shp.TopLeftCell) Is Nothing Then
            If Shp.Name= "shpTest"
                RunMyMacro
                Cancel = True
                Exit Sub
            End If
        End If
    Next Shp
End Sub

Let me know if it fits your needs.

Best regards
OS

 
Posted : 11/04/2025 10:09 pm
Share: