Sendkeys issue with Office365

sathish viswanathan 6 Reputation points
2024-02-13T13:46:28.4933333+00:00

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.

OfficeVersion_Comparison.JPG

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
Microsoft 365 and Office Development Other
Microsoft 365 and Office Install, redeem, activate For business Windows
{count} votes

1 answer

Sort by: Most helpful
  1. sathish viswanathan 6 Reputation points
    2024-02-26T12:40:36.2666667+00:00

    Hi Ruizhi Sun, Yes. this difference is blocking our work. . We've been using SendKey API extensively with capitalized letter.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.