When you write prompts for Copilot in Microsoft 365 apps like Word, Excel, or Outlook, you often repeat the same project name, date range, or client reference across multiple requests. This repetition wastes time and increases the chance of typos. Variables let you define a single piece of information and reuse it throughout a prompt session without retyping it. This article explains how variables work inside Copilot prompts, shows the exact syntax to use, and covers the common mistakes that break variable substitution.
Key Takeaways: How to Use Variables in Copilot Prompts
- Variable syntax
{% raw %}{{variable_name}}{% endraw %}: Wrap variable names in double curly braces inside prompt text to mark them as placeholders. - Variable definition in the first prompt: Define variables at the start of a conversation by writing a clear assignment statement such as
Let client_name = Contoso. - Session scope: Variables remain active only for the current conversation tab in Copilot; closing the tab or starting a new chat resets all variables.
How Variables Work Inside Copilot Prompts
Copilot in Microsoft 365 does not have a built-in variable manager like a programming language. Instead, variables rely on the conversation context. When you write a prompt that includes a variable name wrapped in double curly braces, Copilot remembers the definition you provided earlier in the same session and substitutes the value before generating the response.
The variable syntax is {{variable_name}}. The name must start with a letter and can contain letters, numbers, and underscores. Spaces and special characters other than underscore are not allowed. Copilot treats the variable name as case-insensitive, so {{client_name}} and {{Client_Name}} refer to the same placeholder.
To use a variable, you must first assign it a value in an earlier prompt within the same conversation. The assignment does not require a special command. You simply write a statement that clearly pairs the variable name with its value. For example, in a new Copilot chat in Word, you can type: Set project_name = Q4 Marketing Plan. After that prompt, every time you write {{project_name}} in a subsequent prompt, Copilot replaces it with Q4 Marketing Plan.
Variables are session-scoped. They persist for the duration of the current conversation tab. If you close the tab, refresh the page, or start a new chat, all defined variables are lost. You must redefine them in the new session. This behavior is identical to how Copilot handles conversation history.
What You Need Before Using Variables
To use variables, you need a Copilot license that includes the chat-based prompt interface in Microsoft 365 apps. This includes Copilot for Microsoft 365 and Copilot Pro. The variable substitution works in Word, Excel, PowerPoint, Outlook, and the standalone Copilot chat at copilot.microsoft.com. No additional plugins or admin settings are required. The feature relies on the natural language understanding model in Copilot, which interprets the curly brace syntax as a marker for substitution.
Steps to Define and Use Variables in Copilot Prompts
Follow these steps to create and reuse variables in a single Copilot conversation session.
- Open Copilot in your preferred Microsoft 365 app
Launch Word, Excel, PowerPoint, or Outlook. Click the Copilot icon in the ribbon or the Copilot button in the top-right corner of the app window to open the Copilot pane. - Define a variable in the first prompt
Type a clear assignment statement. Use the formatSet variable_name = valueorLet variable_name = value. For example:Set budget_year = 2025. Press Enter. Copilot confirms the assignment by restating the variable and its value in the response. - Write a prompt that uses the variable
In the same conversation, type a new prompt that includes the variable wrapped in double curly braces. For example:Summarize the sales data for {{budget_year}}. Do not add spaces between the braces and the variable name. - Check that Copilot substituted the value
Review the generated response. Copilot should treat{{budget_year}}as2025. If the response shows the literal text{{budget_year}}instead of2025, the variable was not recognized. Redefine the variable in a new prompt and try again. - Define additional variables as needed
You can define multiple variables in the same session. Each variable must be defined in its own prompt. For example, after definingbudget_year, typeSet region = North America. Then use both variables together:Create a chart of {{region}} revenue for {{budget_year}}. - Update a variable value mid-session
To change a variable, simply redefine it with a new value. TypeSet budget_year = 2026. The new value overwrites the old one for all subsequent prompts in the same session.
Common Mistakes and Limitations When Using Variables
Copilot Shows the Literal Text {{variable_name}} Instead of the Value
This happens when Copilot does not recognize the variable because it was never defined in the current session. The variable definition must occur in a previous prompt in the same conversation tab. If you opened a new chat or refreshed the page, the definition is lost. Redefine the variable and then reuse it in the next prompt.
Variable Name Contains Spaces or Special Characters
Copilot only accepts variable names that start with a letter and contain letters, numbers, and underscores. Spaces, hyphens, periods, and other special characters break the syntax. Use underscores instead of spaces. For example, use client_name instead of client name or client-name.
Variables Defined in One App Do Not Carry Over to Another App
Variables are scoped to the conversation tab in the app where they were defined. If you define project_name in the Copilot pane in Word, that variable is not available in the Copilot pane in Excel, even if both apps are open on the same computer. You must redefine the variable in each app separately.
Long Variable Values Cause Truncation
Copilot has a character limit per prompt. If the value you assign to a variable is very long, such as a full paragraph of text, Copilot may truncate the value during substitution. Keep variable values under 200 characters to avoid this issue.
Variables Do Not Work in System Prompts or Predefined Templates
Variable substitution only occurs in user-written prompts within an active conversation. If you paste a prompt into the Copilot compose box that contains {{variable}} but the variable was not defined in the same session, Copilot treats the text as literal. Variables are not supported in Copilot plugins, Power Automate flows, or custom GPTs built with Copilot Studio unless those tools explicitly include a variable feature.
| Item | Defined Variable | Undefined Variable |
|---|---|---|
| Behavior in prompt | Copilot substitutes the value | Copilot shows literal {{variable}} text |
| Syntax required | Assignment statement earlier in session | No assignment needed but substitution fails |
| Session scope | Current conversation tab only | Never recognized |
| Character limit on value | Keep under 200 characters | Not applicable |
| Cross-app persistence | No | No |
You can now define and reuse variables inside Copilot prompts to avoid retyping project names, dates, client references, and other repeated information. Start each session by defining the variables you need, then reference them with double curly braces in every subsequent prompt. For complex workflows that involve multiple apps, consider saving the variable definitions in a separate text file so you can copy them into each new session quickly. As a next step, try combining variables with Copilot’s file reference feature by writing Summarize {{project_name}} using /Q4_report.docx to see how both shortcuts work together.