web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Sendkey Selective Exec...
Power Automate
Answered

Sendkey Selective Execution

(1) ShareShare
ReportReport
Posted on by 385
When executing a specified method, after selecting the Excel header in the focus window using the PAD, I use Sendkey to execute the formula ={Right:2}-BW1496{Enter}{Up}. This formula shifts the current cell two cells to the right and then subtracts the value of BW1496. After inputting the formula, it returns to its original position.

I've repeatedly tested this process. Each simple 3-line run successfully calculates the result, but inserting it into the main process (10 lines) always fails (it only calculates up to -BW1496). This doesn't change regardless of whether I set an input delay of 50-100 milliseconds, add a 1-second buffer, or use a different variable.

Is this a configuration issue or a bug? Thanks
I have the same question (0)
  • Suggested answer
    Sunil Kumar Pashikanti Profile Picture
    2,095 Moderator on at
     
    Why your 10‑line flow fails (but the 3‑line test works)

    1) Focus drifts
    Even a quick UI event (status bar refresh, tooltip, background dialog, notification) can steal focus for a few milliseconds. In a short test, you usually remain focused; in a longer flow, you often don’t.

    2) Edit mode state differs
    If the target cell is still in edit mode (e.g., after a prior SendKeys typed = or a previous action left the cell in edit), {Right} will move the caret within the formula text instead of moving the active cell. That produces your symptom: you end up with -BW1496 typed, but the navigation didn’t happen.

    3) Excel isn’t ready
    After a selection change or a screen update, Excel may need a fraction of a second to repaint or commit. If you type immediately, the first key can be ignored or applied to the wrong place.

    4) Race conditions from “SendKeys” emulation
    SendKeys simulates keystrokes; it’s best‑effort and not transactional. Small timing differences in a bigger flow change the outcome.
     
    Quick fixes if you must keep SendKeys
    If you’re time‑pressed, try this hardened sequence before your existing key string:

    1) Ensure the window has focus
    Use Focus window (target: your Excel window title).
    Then add a tiny Wait 200–300 ms.
     
    2) Exit any edit mode before navigating
    Prepend {Esc} to your key sequence to guarantee you’re not editing a cell.
    Optional: send {F2}{Esc} (enter edit, then exit) to normalize state.
     
    3) Normalize active cell deterministically
    Use Press keys → Ctrl+g (Go To…) then type a safe anchor like A1 and press {Enter}.
    From there, use {Right} navigation relative to a known anchor (or better, jump to the exact address you want; see next section).
     
    4) Slow it down just a little—strategically
    Instead of a big general delay, add 10–25 ms inter‑key delay only between navigation and text entry boundaries (e.g., after {Right}{Right}, pause 50–100 ms, then type =-BW1496).
     
    5) Break the sequence into atomic steps
    SendKeys: {Esc}
    SendKeys: ^g → Type A1 → {Enter}
    SendKeys: {Right}{Right}
    SendKeys: =-BW1496
    SendKeys: {Enter}{Up}
     
    This reduces the chance a whole chain goes wrong if a single key is missed.
     
    Naming note: Your current string ={Right:2}-BW1496{Enter}{Up} suggests you’re using PAD’s brace‑syntax to repeat keys. That’s fine, but in longer flows it’s often safer to split into multiple Send keys actions so you can insert micro‑waits between navigation and text entry.
     
     
    Prefer to use Excel actions, instead of sending keys.
     
     
    ✅ If this answer helped resolve your issue, please mark it as Accepted so it can help others with the same problem.
    👍 Feel free to Like the post if you found it useful.
  • alee001 Profile Picture
    385 on at
    Sunil Kumar Pashikant, Thank you for your explanation.

    Because there are N open Excel files, PAD only uses header recognition for special operations.

    The starting cell formula varies across different files, but -BW1496 is fixed, hence the need for Sendkey. ={Right:2}-BW1496 is a continuous input action and cannot be split, otherwise the formula will be invalid.

    Because the Excel worksheet calculation is set to manual, there is no delay due to updates or edits. I just don't understand why even with the time extended to 2 seconds, it only executes for the simplest 3 lines, and not multiple lines? Below are the formulas I've tried, and I'm still trying to solve it…

    ={Right}{Right}-BW1496
    ={Right}{Right}%amt% let amt=-BW1496
    ={Right}{Right}{F2}-BW1496
  • Sunil Kumar Pashikanti Profile Picture
    2,095 Moderator on at
     
    Why Sendkeys only works for 3 lines:
    Because focus + edit‑mode timing breaks when multiple Excel windows are open.
     
    Best Fix (no Sendkeys):
    Avoid Sendkeys completely.
    Write the formula directly:
    Use R1C1 formula: =RC[2]-BW1496
     
    Fill it using:
    PAD “Write to Excel worksheet”, or
    A tiny macro: Selection.FormulaR1C1 = "=RC[2]-BW1496"

    Works for all lines at once, no timing issues.
     
    SENDKEYS
    If you do: F2 → = → Right → Right → type -BW1496 → Enter without leaving edit mode, Excel treats it as one continuous formula entry.
    Splitting into separate PAD actions is fine as long as you stay in edit mode (don’t click elsewhere, don’t press Esc, keep the window focused). The arrows will insert references into the formula, not move the selection.
     
    Minimal stable Sendkeys sequence (per cell/range)
         Activate the correct workbook window
         Press F2
         Press =
         Press Right
         Press Right
         Type -BW1496
         Press Enter
    Settings: Delay between keys 75–120 ms, send as hardware keys if available.

    If your PAD supports it, {RIGHT 2} can replace two Right presses—but still send = first while in edit mode.
     
    Why your single string fails
    A combined string like ={Right}{Right}-BW1496 is timing‑sensitive and can hit a state where {Right} moves the cell instead of inserting a reference. Key‑by‑key inside one edit session avoids that.
  • Verified answer
    Assisted by AI
    alee001 Profile Picture
    385 on at
    The default sendkey time is 10ms. After trying 20, 50, 100, and 150ms multiple times, it was finally found that 200ms was needed to stably execute the correct formula.
  • Sunil Kumar Pashikanti Profile Picture
    2,095 Moderator on at
     
    Glad you are able to fix the issue. Please select any of the response that helped you to fix this issue. This can help other community members, thanks!

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the April Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Automate

#1
Vish WR Profile Picture

Vish WR 785

#2
Valantis Profile Picture

Valantis 669

#3
Haque Profile Picture

Haque 563

Last 30 days Overall leaderboard