Hi,
I can manually assign a different sub to each of the 12 function keys using separate Application.OnKey statements in Aut
pen. However the subs are very similar to one another, so it would be better to have a single sub that would know which function key activated it. One way to do this is to again have 12 Application.OnKey statements that would pass the key number to the single sub as a parameter. I was wondering if the 12 statements can be reduced further with a For...Next loop. But I can't get it to work. Perhaps something like this will work, if someone can help me with the syntax, or perhaps I'm on the wrong track altogether.
I can manually assign a different sub to each of the 12 function keys using separate Application.OnKey statements in Aut
Code:
Sub Auto_Open
For x=1 to 12
Application.Onkey "{F" & cstr(x) & "}", "'TestMacro x'"
Next x
End Sub
Sub TestMacro(ByVal y as Integer)
MsgBox "The sub was activated by function key " & y
End Sub
Last edited by a moderator: