Hi Ruizhi Sun, Yes. this difference is blocking our work. . We've been using SendKey API extensively with capitalized letter.
Sendkeys issue with Office365
When using SendKeys to access Excel menus, Office 365 behaves differently from other office versions. Office 365 recognize shortcut keys only with lower case.
For example: SendKeys("%M") doesn't work as expected in Office 365 but works with SendKeys("%m"). Please refer attached snapshots
O365_ UpperCase.png O365_LowerCase.png
Kindly let us know how the keystrokes are processed between the two versions (Office 365 and Office 2021/2016). The following steps have been followed:
- Open your Excel workbook where you want to run the code.
- Press Alt + F11 to open the Visual Basic for Applications (VBA) editor.
- In the VBA editor, go to Insert > Module to insert a new module.
- Copy and paste the provided VBA code into the code window for the new module.
- Close the VBA editor.
- Click on the "Developer" tab in the Excel ribbon
- Add two buttons from the "control" group
- Right-click on the button, and select "Assign Macro."
- In the "Assign Macro" dialog box, select the macro you want to assign to the button from the list and double-click on the button to execute the macro.
Code Snippet :
Sub OpenFormulaMenuUsingSendKeys()
' Send Alt to activate the menu bar, then "M" for the Formulas menu
' Application.SendKeys "%m", True
Application.SendKeys "%M", True
End Sub
Sub OpenViewMenuUsingSendKeys()
' Send Alt to activate the menu bar, then "W" for the View menu
' Application.SendKeys "%w", True
Application.SendKeys "%W", True
End Sub