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..
 

Richard Schollar

MrExcel MVP
Joined
Apr 19, 2005
Messages
23,707
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?
 

partha.raha

New Member
Joined
Sep 30, 2008
Messages
19
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.
 

Richard Schollar

MrExcel MVP
Joined
Apr 19, 2005
Messages
23,707
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
 

partha.raha

New Member
Joined
Sep 30, 2008
Messages
19
Thanks man... this is working... chr$ is not representing the same value as that of ALT key...
can you please help me on this?
 

partha.raha

New Member
Joined
Sep 30, 2008
Messages
19
Moreover with this Chr$ we can only get 256 values..
While with ALT much more combination are available.
 

Richard Schollar

MrExcel MVP
Joined
Apr 19, 2005
Messages
23,707
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
 

partha.raha

New Member
Joined
Sep 30, 2008
Messages
19
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.
 

Richard Schollar

MrExcel MVP
Joined
Apr 19, 2005
Messages
23,707
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
 

Forum statistics

Threads
1,082,601
Messages
5,366,571
Members
400,902
Latest member
fathima

Some videos you may like

This Week's Hot Topics

Top