|
-
Jan 18th, 2011, 05:41 PM
#1
Thread Starter
New Member
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
-
Jan 18th, 2011, 06:00 PM
#2
Re: SendKeys Function and Alt
If you think it's a timing issue, you might try adding a Sleep() API call to your loop.
The time you enjoy wasting is not wasted time.
Bertrand Russell
<- Remember to rate posts you find helpful.
-
Jan 18th, 2011, 06:35 PM
#3
Re: SendKeys Function and Alt
Also, are you positive the Excel sheet has the keyboard focus when you call that loop?
-
Jan 19th, 2011, 03:14 AM
#4
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
Last edited by westconn1; Jan 19th, 2011 at 03:17 AM.
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Jan 19th, 2011, 04:16 AM
#5
Re: SendKeys Function and Alt
Welcome to VBForums 
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
-
Jan 19th, 2011, 09:43 AM
#6
Thread Starter
New Member
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
-
Jan 19th, 2011, 03:59 PM
#7
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
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|