Smart questions
Smart answers
Smart people
Join Eng-Tips Forums
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Member Login




Remember Me
Forgot Password?
Join Us!

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Eng-Tips
*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.
Jobs from Indeed

Link To This Forum!

Partner Button
Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

TomBarsh (Structural) (OP)
22 Feb 07 15:32
I want to use the 'OnKey' VBA command so that some action is taken when a particular key is pressed.

I tried the Excel VBA Help examples, Walkenbach's examples from Power Programming, and a few examples from internet resources. All seemed to use the same basic syntax but it doesn't work for me. Yes, I can use the OnKey command to turn off or restore action. The problem is with directing the action to be taken to a new routine.

For example,

   Sub tom1()
      Application.OnKey "{F1}", "tom2"
   End Sub
   '
   Sub tom2()
      'some action to be taken
   End Sub

Gives error message:  "The macro "c:\myfile.xls'!tom1' cannot be found."

What I finally found is that the macro (in this case, "tom2") was found if all of the code was in the Personal.xls file. Can this be gotten to work if it's in a different file? I have several other files that serve as my "personal.xls" file and I don't really want to be forced to use this file as well.

Thanks.
yogia (Structural)
22 Feb 07 17:01
Hi TomBarsh:

The following code as you posted ...

CODE

Sub tom1()
      Application.OnKey "{F1}", "tom2"
End Sub
'
Sub tom2()
      'some action to be taken
End Sub
works for me. Please note you have to run the macro tom1 first for the F1 key to call and execute the macro tom2.

After I ran the macro tom1, pressing the key F1 called macro tom2 to be run.

And then of course, after testing it I reset the F1 key to its default status by using the statement ...

CODE

      Application.OnKey "{F1}"



Yogi Anand, D.Eng, P.E.
Energy Efficient Building Network LLC
ANAND Enterprises LLC
http://www.energyefficientbuild.com

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!

Back To Forum

Close Box

Join Eng-Tips® Today!

Join your peers on the Internet's largest technical engineering professional community.
It's easy to join and it's free.

Here's Why Members Love Eng-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close