Hello AG,
To your question "Is it possible to run code (macro) when user double
clicks or presses Enter?"
There's no support in Excel Object Model that could listen the KeyPress
event on a cell, however, it is possible to run code when user double click
on a particular cell. The code is shows as below:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As
Boolean)
If Target.Address = "$E$9" Then
MsgBox ""
End If
End Sub
Besides above solution, there's another way to deal with this scenario, we
could create a UserForm in VBA put, buttons in this UserForm, make it like
an Excel 2003 style toolbar.
When use, user could use a shortcut to show this UserForm as modal in
Excel, then he can tab through the buttons, last he could press Space key
to perform the click action.
Detailed steps for this solution:
1 Create UserForm in Excel 2007 please refer to this link:
http://msdn.microsoft.com/en-us/library/dd890502(office.11).aspx#dnofftalk_L
istVBAProcsfromRibbonButton_CreatingtheUserForm
2: Create a macro in Excel 2007 to show this UserForm.
1. On the Tools menu in Microsoft Excel, point to Macro, and then click
Visual Basic Editor.
2. On the Insert menu, click Module.
3. Type or copy your code into the code window of the module.
4. If you want to run the macro (macro: An action or a set of actions
that you can use to automate tasks. Macros are recorded in the Visual Basic
for Applications programming language.) from the module window, press F5.
5. When you're finished writing your macro, click Close and Return to
Microsoft Excel on the File menu.
Code should like this:
Sub Macro1()
'Assume the UserForm just be created is named UserForm1
UserForm1.Show
End Sub
3: Assign Macro1 a shortcut.
1. Go to View tab in Ribbon
2. Click on Macros
3. Select Macro1 in Macros list then click Options...
Best regards,
Tim Li
Microsoft Online Community Support
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).