Is there any Excel marco can get key input while the marco is running?

S

SARA

Is there any Excel marco can get key input while the marco is running?
There is a "get()" commond in Louts 123 do this work.
But it has a different meaning in Excel marco.
Thank you.
 
R

Robert Couchman

Hi Sara,

what exactly are you trying to do, as there are many
commands in excel VB

Robert Couchman
(e-mail address removed)
 
G

Guest

The simplest option is to use the "OnKey" command. It cannot however pick up when a user presses a key while the macro is running very effectively and is designed to be called by one macro which ends and on the keypress it will run another

So I have custom shortcuts for work I run this in my personal workbook (^ stands for the Ctrl key)

Private Sub Workbook_Open(
Application.OnKey "^L", "PasteSpecial
End Su

And this in a module

Private Sub PasteSpecial(
' Keyboard Shortcut: Ctrl+
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= False, Transpose:=Fals
End Su
 
T

Tom Ogilvy

Look at OnKey if you want to assign a specific key combination to a macro.

Other than that, there isn't a built in command. You would have to use the
windows API to read the keyboard buffer.

If you just want to solicit input from the user, use the inputbox or put up
a userform.

I am not familiar with the Lotus Get() command, so It doesn't tell me
exactly what you are looking for.
 
J

jaf

Hi Sara,
Maybe...
Sub test()
MyDate = InputBox("Enter todays date ", GetDate)
Debug.Print MyDate
End Sub

--
John
johnf 202 at hotmail dot com


| Is there any Excel marco can get key input while the marco is running?
| There is a "get()" commond in Louts 123 do this work.
| But it has a different meaning in Excel marco.
| Thank you.
 
S

SARA

Please see the following sample, you will know what I want to do.
I have a marco doing endless calculation in a loop,
only a key is press will stop the marco and print the result.
when can I do in **
Sara

sub sample()
x=1
loop:
x=x+1
**[[ if a key is pressed, goto key_press ]]
goto loop
key_press:
cells(1,1)=x
end sub
 
S

SARA

Tom Ogilvy said:
Look at OnKey if you want to assign a specific key combination to a macro.

Other than that, there isn't a built in command. You would have to use the
windows API to read the keyboard buffer.

If you just want to solicit input from the user, use the inputbox or put up
a userform.

I am not familiar with the Lotus Get() command, so It doesn't tell me
exactly what you are looking for.

Do you know how to use the windows API to read the keyboard buffer?
Thank you.
Sara
 

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