Share via

Automate Copilot in Excel

Ramkumar Ramapathiran 0 Reputation points
2026-05-22T08:33:18.7933333+00:00

Hi, Is it possible to automate opening Copilot in Excel and send a prompt using VBA?

Currently, Copilot in excel seems to work only through the UI, where we have to manually click the Copilot button in the ribbon section and paste the prompt. I want to automate this process so that, with a single click, Excel opens Copilot and enters the prompt automatically.

If this is not possible, are there any alternative approaches to achieve similar automation?

Microsoft 365 and Office | Excel | Other | Windows
0 comments No comments

1 answer

Sort by: Most helpful
  1. Marcin Policht 92,125 Reputation points MVP Volunteer Moderator
    2026-05-22T11:06:10.4566667+00:00

    AFAIK, it is not possible currently to use VBA to directly open the side chat pane or pass a prompt into the user interface of Copilot in Excel. Microsoft does not expose the Copilot sidebar UI components to the VBA COM object model. However, if your goal is to achieve a "one-click" automation that passes a prompt and processes data using Microsoft's AI, then you should be able to to this by leveraging some alternative approaches.

    One would involve the native =COPILOT() worksheet function, which evaluates natural language prompts directly inside cells. Instead of opening the chat sidebar, you can use a standard VBA macro to insert this formula into a specific cell and reference your data range. A basic implementation would look like Range("G1").Formula2 = "=COPILOT(""Summarize the trends in this data"", A1:E10)". Assigning this macro to a clickable shape or form button creates a single-click solution where Excel executes the prompt against your dataset and outputs the AI response directly into your spreadsheet grid.

    Another approach is to utilize direct API calls via VBA to bypass the Excel interface entirely. You can use VBA's MSXML2.ServerXMLHTTP.6.0 object to send HTTP POST requests directly to an AI endpoint, such as the Microsoft Graph Copilot API or Azure OpenAI services. This method requires constructing a JSON payload containing your prompt, appending your API authorization headers, and using a script to send the payload. Once the server responds, your macro can parse the returned text and paste it into any designated cell or dialog box in your workbook.

    If you intend to shift away form VBA, you might consider pairing Office Scripts with Power Automate. You can create a cloud flow triggered by a button within your Excel workbook. This flow can automatically extract the required context from your spreadsheet, pass the data directly to the Microsoft 365 Copilot connector using an automated cloud workflow, capture the generated output, and write the response back into the spreadsheet rows without any manual copy-pasting.

    If you need to interact with the literal sidebar UI pane, you should be able to use the Application.SendKeys method to simulate keyboard shortcuts. This method forces Excel to open the search bar with "%q", types a string like "Chat with Copilot" followed by the enter key "~", waits for the pane to load using Application.Wait, and then attempts to paste or type your prompt. Keep in mind though that this approach is prone to breaking if system latency occurs or if the user clicks out of the window, and is generally not recommended for production environments.


    If the above response helps answer your question, remember to "Accept Answer" so that others in the community facing similar issues can easily find the solution. Your contribution is highly appreciated.

    hth

    Marcin

    Was this answer helpful?

    0 comments No comments

Your answer

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