VBE left-click with / without CTRL pressed down

Thread Starter

atferrari

Joined Jan 6, 2004
4,764
Visual Basic for Excel.

I am not asking about shortcuts.

I need to get different actions for the same command button in a toolbar when:

I left-click on it.
I left-click on it while CTRL key is pressed down.

Edit/ The command button has a macro assigned to it /Edit

How to distinguish between both situations?

My wording for searching failed: I end always reading about shortcuts. :(
 
Last edited:

ErnieM

Joined Apr 24, 2011
8,377
It also helps if you start your search with the letters "VBA" which stands for Visual Basic for Applications.
 

Thread Starter

atferrari

Joined Jan 6, 2004
4,764
Again my thanks to you both for replying.

Problem solved. The right wording is "testing CTRL key"

Found this amongst a few similar solutions.


Rich (BB code):
 Declare Function GetKeyState Lib "user32" _ 
(ByVal nVirtKey As Long) As Integer 
 
Const VK_CONTROL As Integer = &H11 'Ctrl 
 
 
Sub test() 
         If GetKeyState(VK_CONTROL) < 0 Then Ctrl = True Else Ctrl = False 
 
         If Ctrl = True Then 
                 Range("H7").Select 
                 ActiveCell.Value = "apretada" 
     Else 
                 Range("H7").Select 
                 ActiveCell.Value = "sin apretar" 
             End If 
End Sub
 
Top