Use of sendkeys in excel with ALT Key

partha.raha

New Member
Joined
Sep 30, 2008
Messages
19
Hi
I am trying to use a macro to automate the use of alt key.

my code looks like this-->
Private Sub CommandButton1_Click()
For i = 0 To 10
Range("A" & i).Value = ActiveSheet.SendKeys("%" & i)
Next i
End Sub

This code is to enter the value of ALT+1...ALT+10 to column A
Plz help..
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
What exactly do you want to enter in the cells? Alt+1 on my machine doesn't do anything - what exact value do you want in cell A1 at the end of your routine?
 
Upvote 0
Thanks for your quick reply...
If on outlook/word/excel.... u press ALT key and enter any combination of numbers from numpad.. symbols appear.
I want to automate this action for all the combination available.
You can try it yourself on any windows application.
 
Upvote 0
Only if you hit the numbers on the numeric keypad. That's placing simple Ascii characters in the cells. You can do that via:

Code:
Private Sub CommandButton1_Click()
For i = 1 To 10
Range("A" & i).Value = Chr$(i)
Next i
End Sub
 
Upvote 0
Thanks man... this is working... chr$ is not representing the same value as that of ALT key...
can you please help me on this?
 
Upvote 0
I don't know which characters you are looking at because the Alt+1 combination on my computer will not necessarily produce the same results as it does on your computer. If you run the following script whilst you have these symbols added into A1:A10 and copy and paste the resuls in B1:B10 into your reply, I will at least know which codes you are using:

Code:
Sub Codes()
Dim b() As Byte
Dim cell As Range
 
For Each cell In Range("A1:A10")
  b = cell.Value: cell.Offset(,1).Value = b(0) & "(" & b(1) & ")"
Next cell
End Sub
 
Upvote 0
After running the above scrript ... what I got was like
<table x:str="" style="border-collapse: collapse; width: 48pt;" width="64" border="0" cellpadding="0" cellspacing="0"><col style="width: 48pt;" width="64"> <tbody><tr style="height: 12.75pt;" height="17"> <td style="height: 12.75pt; width: 48pt;" width="64" height="17">1(0)</td> </tr> <tr style="height: 12.75pt;" height="17"> <td style="height: 12.75pt;" height="17">2(0)</td> </tr> <tr style="height: 12.75pt;" height="17"> <td style="height: 12.75pt;" height="17">3(0)</td> </tr> <tr style="height: 12.75pt;" height="17"> <td style="height: 12.75pt;" height="17">4(0)</td> </tr> <tr style="height: 12.75pt;" height="17"> <td style="height: 12.75pt;" height="17">5(0)</td> </tr> <tr style="height: 12.75pt;" height="17"> <td style="height: 12.75pt;" height="17">6(0)</td> </tr> <tr style="height: 12.75pt;" height="17"> <td style="height: 12.75pt;" height="17">7(0)</td> </tr> <tr style="height: 12.75pt;" height="17"> <td style="height: 12.75pt;" height="17">8(0)</td> </tr> <tr style="height: 12.75pt;" height="17"> <td style="height: 12.75pt;" height="17">9(0)</td> </tr> <tr style="height: 25.5pt;" height="34"> <td style="height: 25.5pt;" height="34">10(0)</td> </tr> </tbody></table>in Column B.

Using ALT keys I got :
<table x:str="" style="border-collapse: collapse; width: 48pt;" width="64" border="0" cellpadding="0" cellspacing="0"><col style="width: 48pt;" width="64"> <tbody><tr style="height: 12.75pt;" height="17"> <td style="height: 12.75pt; width: 48pt;" width="64" height="17">☺</td> </tr> <tr style="height: 12.75pt;" height="17"> <td style="height: 12.75pt;" height="17">☻</td> </tr> <tr style="height: 12.75pt;" height="17"> <td style="height: 12.75pt;" height="17">♥</td> </tr> <tr style="height: 12.75pt;" height="17"> <td style="height: 12.75pt;" height="17">♦</td> </tr> <tr style="height: 12.75pt;" height="17"> <td style="height: 12.75pt;" height="17">♣</td> </tr> <tr style="height: 12.75pt;" height="17"> <td style="height: 12.75pt;" height="17">♠</td> </tr> <tr style="height: 12.75pt;" height="17"> <td style="height: 12.75pt;" height="17">•</td> </tr> <tr style="height: 12.75pt;" height="17"> <td style="height: 12.75pt;" height="17">◘</td> </tr> <tr style="height: 12.75pt;" height="17"> <td style="height: 12.75pt;" height="17">○</td> </tr> <tr style="height: 25.5pt;" height="34"> <td style="height: 25.5pt;" height="34">◙</td> </tr> </tbody></table>
while you can check the values for chr$ yourself as those can't be copy pasted. Please reply as soon as possible. Thanks in advance.
 
Upvote 0
You got these results:

1(0)
2(0)
3(0)
4(0)
5(0)
6(0)
7(0)
8(0)
9(0)
10(0)

After entering these values into A1:A10:












Are you sure? That isn't at all what I expected. The bracketed zero indicates the standardised Western character set, and if that was the case, then Chr$() should exactly replicate the values.

Let me just be clear - you need to have entered the Alt+1,2,3,4,5,6,7,8,9,10 values into A1:A10 before you run this script:

Code:
Sub Codes()
Dim b() As Byte
Dim cell As Range
 
For Each cell In Range("A1:A10")
  b = cell.Value: cell.Offset(,1).Value = b(0) & "(" & b(1) & ")"
Next cell
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,849
Members
452,361
Latest member
d3ad3y3

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top