• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Design a macro which will get activated when user enters some specific keys

ThrottleWorks

Excel Ninja
Sir,


I am asking this question on my friend’s behalf.

I am trying to help him on a project.


We want to design a macro which will get activated when user enters some specific keys on the keyboard.


We have different products, such as A B C D.

Each product has a different image.

For example if the user types A on the keyboard, the image for product A should appear in the cell.


I think I may be able to do the “populating the image” part but I do not know how to link vb with keyboard strokes.


Is it possible, can anyone help in this please.
 
You sure you want just the letter? That could get it to be triggered more often than you'd like if the user is typing a regular word with a/b/c/d in it. You could make it so that different macros have Ctrl+a as the shortcut to activate them?


If you *really* want to go this route, you can use the Auto_Open macro to reassign keys like so:

[pre]
Code:
Sub Auto_Open()
Application.OnKey "a", "MyAMacro"
Application.OnKey "b", "MyBMacro"

End Sub
and to reset the keys:

Sub Auto_Close()

Application.OnKey "a"
Application.OnKey "b"
End Sub
[/pre]
With MyAMacro and MyBMacro being specific macros.
 
Yes Sir, I got your point, I will rethink about it, thanks a lot for the help.Have a nice day,


And then this might go out of my control. Thanks for the warning, i had not thought about it.


may be I should have a list, the user will selet the product name & the procudt image apears.


That will be more safe, once again, thanks a lot for helping me.
 
You may use Worksheet_Change Event for the specific sheet and a specific column where product code will appear.

Something like:

[pre]
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 2 Then 'It will trigger only for column B
Select Case Target.Value
Case "A"
'Case A macro call here
Case "B"
'Case A macro call here
Case "C"
'Case A macro call here
Case "D"
'Case A macro call here
End Select
End If
End Sub
[/pre]
 
Back
Top