0

I plan to manually select the target Chrome tab and press the macro button from Excel to use it like an on-screen keyboard.

I would like to operate the Chrome browser using only Sendkeys, a standard feature of Excel VBA. SeleniumVBA is not used.

I checked the behavior of sendkeys when multiple Chrome browser windows and multiple tabs were open. As a result, input was only entered in the last selected tab.

Is it okay to understand that SendKeys only works on the tab that the user last operated on? Please let me know if you have any other knowledge.

Sub SendK()   'Activate Chrome app Call AppActivate("Chrome")          'Keystroke   SendKeys "ABC"   SendKeys "{Enter}" End Sub 
3
  • 1
    Working with SendKeys is unreliable. Most of the time, it might work as you would like it to, but sometimes it can fail. Therefore, there is no guarantee it will always work on the tab the user last used. Commented Jun 16, 2024 at 7:14
  • thank you for your reply. I understand that SendKeys may behave unintended in some cases. Commented Jun 18, 2024 at 9:29
  • Yes, please see my answer. Commented Jun 18, 2024 at 9:31

1 Answer 1

1

SendKeys operates on the currently active window. This means that if you have multiple Chrome windows and tabs open, the keystrokes will be sent to the tab that was last active or interacted with.

Unreliable Behavior: While SendKeys can work as intended most of the time, its reliability can be inconsistent, especially in scenarios with multiple applications running. This inconsistency arises because SendKeys relies on the current focus of the operating system, which can be affected by various factors such as system alerts, other applications stealing focus, or user actions.

One of the known issues with SendKeys in VBA is that it can interfere with the state of NumLock. This can be particularly troublesome if your users rely on the NumLock state for data entry. Here you find a fix for this behaviour

You might want to consider using API calls

Sign up to request clarification or add additional context in comments.

1 Comment

thank you for your reply. I now understand the cases in which SendKeys exhibits unintended behavior and the countermeasures.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.