Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Why doesn't OnKey work?

I have the following two subs below. From the help files, it's my
understanding that after running sub "setit", I should be able to do a
"Control s" and then sub "doit" will be called. It doesn't work. I have
Excel 2003. Am I misunderstanding the usage of ONKEY or what am I doing
wrong??

Thanks for any help

Sub doit()
Dim aa
aa = aa
End Sub

Sub setit()
Application.OnKey "^s", "doit"
End Sub


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Why doesn't OnKey work?

Sub doit()
Dim aa
aa = aa
MsgBox "In Doit"
End Sub

Sub setit()
Application.OnKey "^s", "doit"
End Sub

Sub Unsetit()
Application.OnKey "^s"
End Sub


worked fine for me.

--
Regards,
Tom Ogilvy


"Mike" wrote in message
...
I have the following two subs below. From the help files, it's my
understanding that after running sub "setit", I should be able to do a
"Control s" and then sub "doit" will be called. It doesn't work. I have
Excel 2003. Am I misunderstanding the usage of ONKEY or what am I doing
wrong??

Thanks for any help

Sub doit()
Dim aa
aa = aa
End Sub

Sub setit()
Application.OnKey "^s", "doit"
End Sub




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 210
Default Why doesn't OnKey work?

Mike,

I believe the onKey command has to be a continue run mode. You are running
it once expecting a key capture. I believe it needs contstant polling. You
should have the setit command call itself & code in a keystroke to end the
entire process.
--
http://HelpExcel.com

516-984-0252


"Mike" wrote:

I have the following two subs below. From the help files, it's my
understanding that after running sub "setit", I should be able to do a
"Control s" and then sub "doit" will be called. It doesn't work. I have
Excel 2003. Am I misunderstanding the usage of ONKEY or what am I doing
wrong??

Thanks for any help

Sub doit()
Dim aa
aa = aa
End Sub

Sub setit()
Application.OnKey "^s", "doit"
End Sub



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Why doesn't OnKey work?

No, that isn't true.

--
Regards,
Tom Ogilvy


"galimi" wrote in message
...
Mike,

I believe the onKey command has to be a continue run mode. You are
running
it once expecting a key capture. I believe it needs contstant polling.
You
should have the setit command call itself & code in a keystroke to end the
entire process.
--
http://HelpExcel.com

516-984-0252


"Mike" wrote:

I have the following two subs below. From the help files, it's my
understanding that after running sub "setit", I should be able to do a
"Control s" and then sub "doit" will be called. It doesn't work. I have
Excel 2003. Am I misunderstanding the usage of ONKEY or what am I doing
wrong??

Thanks for any help

Sub doit()
Dim aa
aa = aa
End Sub

Sub setit()
Application.OnKey "^s", "doit"
End Sub





  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Why doesn't OnKey work?

Just an added thought, all the code should be in a general module, not in a
worksheet or the thisworkbook module.

--
Regards,
Tom Ogilvy

"Tom Ogilvy" wrote in message
...
Sub doit()
Dim aa
aa = aa
MsgBox "In Doit"
End Sub

Sub setit()
Application.OnKey "^s", "doit"
End Sub

Sub Unsetit()
Application.OnKey "^s"
End Sub


worked fine for me.

--
Regards,
Tom Ogilvy


"Mike" wrote in message
...
I have the following two subs below. From the help files, it's my
understanding that after running sub "setit", I should be able to do a
"Control s" and then sub "doit" will be called. It doesn't work. I have
Excel 2003. Am I misunderstanding the usage of ONKEY or what am I doing
wrong??

Thanks for any help

Sub doit()
Dim aa
aa = aa
End Sub

Sub setit()
Application.OnKey "^s", "doit"
End Sub








  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,365
Default Why doesn't OnKey work?

Works for me. Try replacing aa=aa in your doit routine with
MsgBox "You pressed [Ctrl]+[S]"

just to verify that it is (or isn't) happening.

I put my code in a regular code module, not in worksheet or workbook
modules, and it worked like a champ. Excel 2003, Windows XP Pro.
Sub CalledRoutine()
MsgBox "You pressed [Ctrl]+[S]"
End Sub
Sub SetItUp()
Application.OnKey "^s", "CalledRoutine"
End Sub


"Mike" wrote:

I have the following two subs below. From the help files, it's my
understanding that after running sub "setit", I should be able to do a
"Control s" and then sub "doit" will be called. It doesn't work. I have
Excel 2003. Am I misunderstanding the usage of ONKEY or what am I doing
wrong??

Thanks for any help

Sub doit()
Dim aa
aa = aa
End Sub

Sub setit()
Application.OnKey "^s", "doit"
End Sub



  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default Why doesn't OnKey work?

I thought that "^s" was normally used in keystoke to save a file.

"JLatham" wrote:

Works for me. Try replacing aa=aa in your doit routine with
MsgBox "You pressed [Ctrl]+[S]"

just to verify that it is (or isn't) happening.

I put my code in a regular code module, not in worksheet or workbook
modules, and it worked like a champ. Excel 2003, Windows XP Pro.
Sub CalledRoutine()
MsgBox "You pressed [Ctrl]+[S]"
End Sub
Sub SetItUp()
Application.OnKey "^s", "CalledRoutine"
End Sub


"Mike" wrote:

I have the following two subs below. From the help files, it's my
understanding that after running sub "setit", I should be able to do a
"Control s" and then sub "doit" will be called. It doesn't work. I have
Excel 2003. Am I misunderstanding the usage of ONKEY or what am I doing
wrong??

Thanks for any help

Sub doit()
Dim aa
aa = aa
End Sub

Sub setit()
Application.OnKey "^s", "doit"
End Sub



  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Why doesn't OnKey work?

With a little bit more experimenting, it appears that it works if I'm typing
into a WorkSheet but I was hoping that it would work when a Userform had the
focus.

Hopefull thinking, huh!!

"Mike" wrote in message
...
I have the following two subs below. From the help files, it's my
understanding that after running sub "setit", I should be able to do a
"Control s" and then sub "doit" will be called. It doesn't work. I have
Excel 2003. Am I misunderstanding the usage of ONKEY or what am I doing
wrong??

Thanks for any help

Sub doit()
Dim aa
aa = aa
End Sub

Sub setit()
Application.OnKey "^s", "doit"
End Sub




  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,718
Default Why doesn't OnKey work?

but I was hoping that it would work when a Userform had the focus.

Too bad you didn't think to mention that in your original post.

--
Jim
"Mike" wrote in message
...
With a little bit more experimenting, it appears that it works if I'm
typing into a WorkSheet but I was hoping that it would work when a
Userform had the focus.

Hopefull thinking, huh!!

"Mike" wrote in message
...
I have the following two subs below. From the help files, it's my
understanding that after running sub "setit", I should be able to do a
"Control s" and then sub "doit" will be called. It doesn't work. I have
Excel 2003. Am I misunderstanding the usage of ONKEY or what am I doing
wrong??

Thanks for any help

Sub doit()
Dim aa
aa = aa
End Sub

Sub setit()
Application.OnKey "^s", "doit"
End Sub






  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,365
Default Why doesn't OnKey work?

You're correct, that is the normal definition. But using the .OnKey function
will change that definition! To set it back to the default, you would use
Application.OnKey "^s"
without the second parameter.

"JLGWhiz" wrote:

I thought that "^s" was normally used in keystoke to save a file.

"JLatham" wrote:

Works for me. Try replacing aa=aa in your doit routine with
MsgBox "You pressed [Ctrl]+[S]"

just to verify that it is (or isn't) happening.

I put my code in a regular code module, not in worksheet or workbook
modules, and it worked like a champ. Excel 2003, Windows XP Pro.
Sub CalledRoutine()
MsgBox "You pressed [Ctrl]+[S]"
End Sub
Sub SetItUp()
Application.OnKey "^s", "CalledRoutine"
End Sub


"Mike" wrote:

I have the following two subs below. From the help files, it's my
understanding that after running sub "setit", I should be able to do a
"Control s" and then sub "doit" will be called. It doesn't work. I have
Excel 2003. Am I misunderstanding the usage of ONKEY or what am I doing
wrong??

Thanks for any help

Sub doit()
Dim aa
aa = aa
End Sub

Sub setit()
Application.OnKey "^s", "doit"
End Sub



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
application.onkey doesn't work within a cell [email protected] Excel Programming 1 September 27th 06 12:09 AM
Onkey doesn't work Stefi Excel Programming 7 April 13th 06 02:02 PM
onkey help wardy Excel Programming 0 July 20th 04 05:49 PM
application.onkey doesn't work bob Excel Programming 2 May 10th 04 11:06 AM
onkey peter Excel Programming 2 March 2nd 04 07:34 PM


All times are GMT +1. The time now is 12:17 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"