A negative to using Application.Onkey

G

Guest

I have programmed an excel spreadsheet to activate a macro when the ENTER
button is pressed using the Application.Onkey command.

My problem is that if I then open another excel spreadsheet, and I press
ENTER, then the macro for the 1st speadsheet tries to run.

Is there a way to ensure that this macro runs only in the specific
speadsheet and not in every speadsheet I have open?

NB/ I have currently written the onkey command into Sheet1 of Microsoft
Excel Objects for the speadsheet.

Thanks
 
B

Bob Phillips

Set the key on the worbook activate event, and reset it on the workbook
deactivate event.

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)
 
B

Bob Phillips

Do you understand that Workbook activate and deactivate code MUST go in the
ThisWorkbook code module?

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)
 
G

Guest

No - I can accept this but I don't understand why. The activate and
deactivate events are available for each sheet, but I will follow your
instruction.
Thanks
 
B

Bob Phillips

They are, but we are talking about WORKBOOK activate,deactivate.

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)
 
G

Guest

Bob, you need to change your name to "The Oracle".

All done and working. Big Thanks.
Andy
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top