Notifications
Clear all
VBA & Macros
3
Posts
3
Users
0
Reactions
120
Views
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
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
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