How to Create Macros: A Practical Guide with Examples

Macros automate repetitive tasks by recording or scripting a sequence of actions you’d otherwise perform manually. You create one, assign it a shortcut or abbreviation, and it executes the whole sequence on demand.

The term covers a wide range of tools: recorded Excel routines that format reports, keyboard hotkeys that open apps, and text expansion Snippets that turn a short abbreviation into a full email. Same concept, different contexts.

This guide covers creating macros in the most common environments: Excel, Google Sheets, Word, and TextExpander. Each section stands alone, so skip to whichever matches your workflow. Updated May 2026.

What are macros?

A macro is a saved sequence of actions that runs on command. In Microsoft Excel, a macro might select a range, apply formatting, and insert a formula, all triggered by a single keyboard shortcut. In a text expansion tool like TextExpander, a macro turns an abbreviation like ;addr into a full business address wherever you type it.

Two main approaches:

Recorded macros: You perform the actions manually while software captures them. No code required.

Scripted macros: You write instructions in a programming language like VBA or JavaScript. More control, steeper learning curve.

Most people start with recording. Scripting becomes useful when you need conditional logic or loops.

Types of macros

The word “macro” means different things depending on context.

Spreadsheet macros are built into Microsoft Excel and Google Sheets. They automate data manipulation, formatting, and calculations using VBA (Excel) or Google Apps Script (Sheets).

Text expansion macros (tools like TextExpander) convert abbreviations into longer text, templates, or dynamic content. Dates, fill-in fields, conditional output. The kind of repetitive typing that adds up to hours per week.

Keyboard and hotkey macros use tools like AutoHotkey and Keyboard Maestro to assign complex action sequences to a single key combination: opening apps, clicking through menus, typing long strings.

Application macros exist inside specific software: Photoshop actions, browser DevTools snippets, AutoCAD macros. Different systems, same underlying idea.

How to create a macro in Excel

Excel macros are stored in your workbook as VBA code. You can record them without writing a line of code, or write them from scratch in the Visual Basic Editor.

Record a macro in Excel on Windows

Step 1: Enable the Developer tab

The Developer tab is hidden by default.

  1. Open Excel and go to File > Options.
  2. Select Customize Ribbon.
  3. Under Main Tabs, check Developer.
  4. Click OK.

Step 2: Record the macro

  1. On the Developer tab, click Record Macro.
  2. Give it a name (no spaces), assign an optional shortcut key, and choose where to store it. This Workbook works for most cases.
  3. Click OK, then perform the actions you want to automate.
  4. Click Stop Recording on the Developer tab when done.

Step 3: Run the macro

Go to Developer > Macros, select yours, and click Run. Or press the shortcut key you assigned.

Step 4: Save as a macro-enabled file

Excel macros don’t survive in .xlsx format. When you close the file, Excel prompts you to save as a Macro-Enabled Workbook (.xlsm). Choose that format. Otherwise the macro won’t be there when you reopen the file.

Record a macro in Excel on Mac

  1. Go to Excel > Preferences > Ribbon & Toolbar.
  2. Under Main Tabs, enable Developer.
  3. On the Developer tab, click Record Macro.
  4. Configure the name and shortcut, then click OK.
  5. Perform your actions, then click Stop Recording.

Write a macro from scratch in VBA

Recording handles straightforward sequences. For loops, conditionals, or anything dynamic, you need VBA.

  1. On the Developer tab, click Visual Basic, or press Alt+F11 on Windows.
  2. In the Visual Basic Editor, go to Insert > Module.
  3. Type your macro. The simplest possible example:
Sub HelloWorld()
    MsgBox "Hello, World!"
End Sub
  1. Press F5 to run it.

For real work, macros do something more useful. Here’s one that scans a column for past dates and highlights them red, useful for any report tracking deadlines or overdue items:

Sub HighlightOverdue()
    Dim i As Integer
    For i = 2 To 100
        If Cells(i, 3).Value < Date And Cells(i, 3).Value <> "" Then
            Cells(i, 3).Font.Bold = True
            Cells(i, 3).Font.Color = RGB(255, 0, 0)
        End If
    Next i
End Sub

This loops through rows 2–100, checks column C for non-empty dates earlier than today, and applies bold red formatting to matches. Adjust the column number and row range to fit your spreadsheet.

Security note: Excel macros can run code automatically when a file opens. Before enabling macros in a file from an untrusted source, check your settings at Developer > Macro Security.

How to create a TextExpander Snippet

TextExpander handles text expansion. You define an abbreviation and the full text it represents. Type the abbreviation in any text field (Outlook, Slack, a browser form, a support ticket) and TextExpander replaces it with the full content instantly.

Create a basic text Snippet

  1. Open TextExpander and click + to create a new Snippet.
  2. In the Content field, type the text you want to expand. Example: “Thank you for reaching out. I’ll follow up within one business day.”
  3. In the Abbreviation field, enter a short trigger, like tyreply.
  4. Save.

Type tyreply anywhere and TextExpander expands it.

Add fill-in fields for variable content

Static text is useful. Snippets with fill-in fields are more useful. In the Snippet editor, click the fill-in field button in the toolbar to insert a named placeholder. When the Snippet expands, TextExpander shows a small form. You fill in the variable parts, and the rest of the text stays identical every time.

A support response Snippet, similar to a canned response, with fill-in fields might look like:

Hi [First name],

Thank you for writing in about [Issue description].
I've flagged this and will follow up by [Date].

Every rep uses the same structure. Only the customer-specific details change.

Use date macros

TextExpander can insert today’s date automatically using a built-in date macro. In the Snippet editor, click the date macro button and choose your format. The date inserts at expansion time, always current, not the date you saved the Snippet.

Share Snippets with your team

On a Business or higher plan, you can share Snippet Groups with teammates. When you update a Snippet, everyone on the team gets the change immediately. For teams managing consistent messaging across support, sales, or operations, that real-time propagation is the feature that matters most. TextExpander customers report saving thousands of hours on repetitive typing. Virta Health documented 69,000 hours saved over 12 months. See pricing for plan details, or browse customer service response examples for ready-to-use Snippets your team can deploy on day one. Learn more about text snippets and how they work.

Create Snippets with AI

The TextExpander MCP Server connects your Snippet library directly to AI assistants that support the Model Context Protocol (MCP). Instead of opening TextExpander to build or edit Snippets, you can create them through conversation with your AI assistant.

Once connected, you can ask your assistant to create Snippet Groups, add Snippets with fill-in fields and date macros, search your library, or update existing Snippets in bulk. The assistant handles the macro syntax automatically. You describe what you want, it builds the Snippet.

For example:

“Create a Snippet Group called ‘Support Templates’ and add a Snippet with the abbreviation ;thanks that says ‘Thank you for your email. I’ll get back to you within 24 hours.'”

Compatible AI platforms include Claude Desktop, ChatGPT (Pro, Team, or Enterprise with Developer Mode), and Microsoft Copilot Studio. Any TextExpander plan works. Existing team permissions carry over. Members can only access Snippets they already have access to in TextExpander.

Setup takes about 3 minutes. See the MCP Server Getting Started Guide for full instructions.

How to create a macro in Google Sheets

Google Sheets has had a built-in macro recorder since 2018. It records your actions as Google Apps Script, which is JavaScript-based.

  1. In Sheets, go to Extensions > Macros > Record macro.
  2. A toolbar appears at the bottom. Choose Use absolute references (records exact cell positions) or Use relative references (records movement relative to your cursor).
  3. Perform the actions you want to automate.
  4. Click Save in the recording toolbar. Give the macro a name.
  5. To run it: Extensions > Macros > select your macro.

On first run, Google asks you to authorize the macro. This is expected behavior. Macros are stored as Apps Script files attached to the spreadsheet; go to Extensions > Apps Script to edit the code directly.

How to create a macro in Microsoft Word

Word macros work the same way as Excel macros: same Developer tab, same VBA engine, same recording process.

  1. Enable the Developer tab if needed: File > Options > Customize Ribbon > check Developer.
  2. On the Developer tab, click Record Macro.
  3. In the dialog, choose whether to assign it a Button (adds it to the Quick Access Toolbar) or a Keyboard shortcut.
  4. Click OK and perform your actions.
  5. Click Stop Recording on the Developer tab.

A practical use case: a macro that inserts a formatted letterhead (logo, title, contact info) with a single toolbar button. Assign it in step 3 and it’s one click, every time, with consistent formatting.

Can ChatGPT help you write a macro?

Yes. It handles Excel VBA and Google Apps Script competently for standard tasks. Worth trying before writing anything from scratch.

A useful prompt structure:

“Write a VBA macro for Excel that loops through column A and highlights any cell containing the word ‘pending’ in yellow.”

Paste the output into your Visual Basic Editor and test on a copy of your file first. ChatGPT won’t know your specific spreadsheet layout, so some adjustment is usually needed. Treat it as a starting draft.

If you use AI tools regularly, you can store your most effective prompts in TextExpander Snippets. Trigger the prompt with an abbreviation, fill in the variable details at expansion time, and paste directly into ChatGPT. When you refine a prompt, one update in TextExpander propagates to the whole team.

Tools for creating macros

TextExpander handles text expansion macros across every app on Mac, Windows, iPhone, iPad, and Chrome. No API setup. Snippets work in ChatGPT, Outlook, Zendesk, Slack, and any other text field. Individual and team plans available. See pricing.

AutoHotkey is free and open-source for Windows. It automates keystrokes, mouse clicks, and window management. Scripting uses its own language but the community documentation is extensive. See AutoHotkey alternatives if you want a visual interface.

Keyboard Maestro is the most capable macro tool for Mac. Records and scripts complex workflows, triggers macros by schedule or event, handles multi-app automation. One-time purchase, Mac-only. See Keyboard Maestro alternatives for cross-platform options.

Microsoft Excel and Word include a full macro recorder and VBA editor with no additional software needed. The natural choice if you’re already in Microsoft 365.

Google Sheets includes a recorder and a full Apps Script editor, useful for cloud-based automation that multiple people need to run.

Macro Recorder captures mouse and keyboard sequences on Windows and Mac, then replays them with precision. Useful for automating tasks that span multiple applications. For a broader comparison, see the best macros software roundup.

Frequently asked questions

What’s the easiest macro to create?

A text expansion Snippet in TextExpander. Open the app, type your content, set an abbreviation, save. No recording, no coding. It works in every app immediately.

Are macros safe?

Macros you create yourself carry no risk. The concern is receiving Excel files from unknown sources. A macro-enabled file that auto-runs VBA on open is a known malware vector. Your own macros, or macros from trusted colleagues, are safe. Review your settings at Developer > Macro Security in Excel if you regularly open files from outside your organization.

Can I create macros on a Mac?

Yes. Excel for Mac has the same Developer tab and macro recorder as Windows. The path to enable it is slightly different (covered above). TextExpander runs natively on Mac. Keyboard Maestro is Mac-only and well-suited for complex workflows. AutoHotkey is Windows-only, but Mac has Automator as a built-in alternative for system-level tasks.

What’s the difference between a macro and a script?

A macro is a saved sequence of actions (recorded or written) that execute on command. A script is any code that automates something. All Office macros are scripts (VBA). All Google Sheets macros are Apps Script. The terms overlap significantly in practice; people use them interchangeably.

The right tool depends on what you’re automating. Excel’s recorder handles spreadsheet work without code. TextExpander handles text in any app, with fill-in fields and team sharing built in. Google Sheets adds the same recorder for cloud-based work. AutoHotkey and Keyboard Maestro handle system-level automation across multiple programs. Learn more about how to automate data entry for more on repetitive typing workflows.

Start with whatever context matches your most repetitive task. The concepts transfer once you’ve built one.