VBA: SendKeys for the Mac

Domenic

MrExcel MVP
Joined
Mar 10, 2004
Messages
21,801
Office Version
  1. 365
Platform
  1. Windows
Can someone please confirm for me whether or not the 'SendKeys' statement is available for the Mac (Excel v.X). When I try something as simple as...

Code:
SendKeys "ABC"

...I receive the following error...

Code:
"Run-time error '5':

Invalid procedure call or argument"

Thanks!
 
You can also make a sentence by using the following code:

MacScript ("tell application " & Chr(34) & "System Events" & Chr(34) & " to keystroke " & Chr(34) & "Hello World!" & Chr(34))

Just Replace "Hello World!" with whatever you want it to say... Hope that helps.
 
Upvote 0

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
for mac use:

MacScript ("tell application " & Chr(34) & "System Events" & Chr(34) & " to keystroke " & Chr(34) & "ABC" & Chr(34))
 
Upvote 0
I'm not longer using the Mac version for Excel, but others may find this useful.

Thanks!
 
Upvote 0
Thanks 1k times, this was exactly what I needed!

Try using:

MacScript ("tell application " & Chr(34) & "System Events" & Chr(34) & " to key code 7") 'this will type the letter "x"

' I use this for my validation dropdown lists to automate the dropdown action when the cell is clicked:
MacScript ("tell application " & Chr(34) & "System Events" & Chr(34) & " to key code 126 using option down")

'You can also use the "Control", "Command" & "Option" Keys:
'tell application "System Events" to keystroke "f" using {control down, command down, option down}

'Key Code numbers are as follows:
'0 = a
'1 = s
'2 = d
'3 = f
'4 = h
'5 = g
'6 = z
'7 = x
'8 = c
'9 = v
'10 = ISO_Section
'11 = b
'12 = q
'13 = w
'14 = e
'15 = r
'16 = y
'17 = t
'18 = 1
'19 = 2
'20 = 3
'21 = 4
'22 = 6
'23 = 5
'24 = (Equal)
'25 = 9
'26 = 7
'27 = (Minus)
'28 = 8
'29 = 0 (number 0)
'30 = (RightBracket)
'31 = o (letter "o")
'32 = u
'33 = (LeftBracket)
'34 = i (Letter "eye")
'35 = p
'36 = (Return)
'37 = l (Letter "el")
'38 = j
'39 = (Quote)
'40 = k
'41 = (Semicolon)
'42 = (Backslash)
'43 = (Comma)
'44 = (Slash)
'45 = n
'46 = m
'47 = (Period)
'48 = (Tab)
'49 = (Space)
'50 = ANSI_Grave
'51 = (Delete)
'53 = (Escape)
'55 = (Command)
'56 = (Shift)
'57 = (CapsLock)
'58 = (Option)
'59 0x3B Control
'60 0x3C RightShift
'61 0x3D RightOption
'62 0x3E RightControl
'63 0x3F Function
'64 0x40 F17
'65 0x41 ANSI_KeypadDecimal
'67 0x43 ANSI_KeypadMultiply
'69 0x45 ANSI_KeypadPlus
'71 0x47 ANSI_KeypadClear
'72 0x48 VolumeUp
'73 0x49 VolumeDown
'74 0x4A Mute
'75 0x4B ANSI_KeypadDivide
'76 0x4C ANSI_KeypadEnter
'78 0x4E ANSI_KeypadMinus
'79 0x4F F18
'80 0x50 F19
'81 0x51 ANSI_KeypadEquals
'82 0x52 ANSI_Keypad0
'83 0x53 ANSI_Keypad1
'84 0x54 ANSI_Keypad2
'85 0x55 ANSI_Keypad3
'86 0x56 ANSI_Keypad4
'87 0x57 ANSI_Keypad5
'88 0x58 ANSI_Keypad6
'89 0x59 ANSI_Keypad7
'90 0x5A F20
'91 0x5B ANSI_Keypad8
'92 0x5C ANSI_Keypad9
'93 0x5D JIS_Yen
'94 0x5E JIS_Underscore
'95 0x5F JIS_KeypadComma
'96 0x60 F5
'97 0x61 F6
'98 0x62 F7
'99 0x63 F3
'100 0x64 F8
'101 0x65 F9
''102 0x66 JIS_Eisu
'103 0x67 F11
'104 0x68 JIS_Kana
'105 0x69 F13
'106 0x6A F16
'107 0x6B F14
''109 0x6D F10
'111 0x6F F12
'113 0x71 F15
'114 0x72 Help
'115 0x73 Home
'116 0x74 PageUp
'117 0x75 ForwardDelete
'118 0x76 F4
'119 0x77 End
'120 0x78 F2
'121 0x79 PageDown
'122 0x7A F1
'123 0x7B LeftArrow
'124 0x7C RightArrow
'125 0x7D DownArrow
'126 0x7E UpArrow
 
Upvote 0

Forum statistics

Threads
1,224,825
Messages
6,181,190
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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