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.
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
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
A Shape does not have a Double_Click property'
I think the only way you are going to get this to work is not to use a button!
Instead you need to Select a range of cells, merge them add a colour fill and whatever text you want.
You can then use that as a "Button", because it is a range not a shape then it will have a Double_Click property.
In the Sheet object module:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Dim r As Range
Set r = Range("btnRange")
If Not Intersect(Target, r) Is Nothing Then MyMacro
End Sub
And in a Standard module
Sub MyMacro()
MsgBox "MyMacro running"
End Sub
I am attaching a file with this method working.