SendKeys Function and Alt
Hello,
Within Excel I am iterating through a loop trying to perform the equivalent of typing 'Alt+1','Alt+2' etc., using SendKeys function. I'm pretty sure it's a timing issue, ie key release and posting http://www.vbforums.com/showthread.php?t=536446, user anhn explains the differences between special character keys and when they are released etc. I have not found a way to get this to work. The code below it simply iterates through spreadsheet and nothing is populated.
I've tried probably 30 permuations with SendKeys function, to no avail.
Many thanks.....Mick
Sub ASCII()
Dim iTmp As Long
Range("A1").Select
For iTmp = 1 To 15
SendKeys "%" & iTmp, True
ActiveCell.Offset(1, 0).Select
Next iTmp
End Sub
Re: SendKeys Function and Alt
If you think it's a timing issue, you might try adding a Sleep() API call to your loop.
Re: SendKeys Function and Alt
Also, are you positive the Excel sheet has the keyboard focus when you call that loop?
Re: SendKeys Function and Alt
i copied and pasted the code into excel, but of course as this is on w7, i just get permission denied for sendkeys
if this is not resolved i will test in the morning on xp
also note: that sending some of those alt keystrokes may clear the worksheet
Re: SendKeys Function and Alt
Welcome to VBForums :wave:
Thread moved to 'Office Development/VBA' forum... note that while it certainly isn't made clear, the "VB Editor" in Office programs is actually VBA rather than VB, so the 'VB6' forum is not really apt
Re: SendKeys Function and Alt
First off, thanks for all the responses. Glad to be aboard. Ok I tweaked the code and ran exactly what you see below. Resulted in col A, rows 10-15 populated with integer values 0,1,2,3,4,5; ie each cell has single integer. Curiously, rows 1-9 are blank.
Sub ASCII()
Dim iTmp As Long
Range("A1").Select
For iTmp = 1 To 15
SendKeys "%" & iTmp, True
SendKeys "~", True
Next iTmp
End Sub
Re: SendKeys Function and Alt
note: when sending alt & number keys combinations to screen or file, it is specific to number pad keys, not ascii values,
eg alt 155 from number pad will produce ¢, alt 0189 like ½
the same combinations from the qwerty keys produce nothing at all
sendkeys only sends ascii values, so can not differentiate