What Is a Macro in Microsoft? Definition & Uses
In this article
A macro in Microsoft software is a saved set of instructions that automates repetitive tasks. In Microsoft 365 apps such as Word, Excel, PowerPoint, and Outlook, macros are most often written in Visual Basic for Applications (VBA), Microsoft's built-in programming language. When you run a macro, the application executes those instructions step by step — formatting a document, cleaning up a spreadsheet, or sending a routine email — without you clicking through each action manually. Macros are standard, documented features of Microsoft Office, not slang or informal terms; the word comes from the Greek makros (long, large) and entered computing in the 1950s to describe a single instruction that expands into many machine-level instructions.
Background: Where the Term Comes From
The word "macro" predates Microsoft Office by decades. In early assembly-language programming, a macro was a shorthand name for a block of instructions; the assembler expanded the name into the full block before running it. The idea migrated into productivity software in the 1980s, when spreadsheet programs like Lotus 1-2-3 introduced recorded keystroke macros. Microsoft added a macro recorder to Excel and Word in the 1990s and standardized on VBA as the underlying language. Today "macro" in a Microsoft context almost always means a VBA procedure stored inside a document, workbook, presentation, or mailbox — not a keyboard macro in the general sense, though the concept is the same: one trigger, many actions.
How Macros Work in Microsoft Office
A macro is stored either in the document itself or in a personal template. In Word, macros typically live in the document or in the Normal.dotm template; in Excel, they live in the workbook or in the Personal Macro Workbook. The most common ways to create one are:
- Record a macro: The application watches your clicks and keystrokes and writes the equivalent VBA code. This is the easiest entry point and works well for formatting and simple data entry.
- Write VBA manually: Open the Visual Basic Editor (Alt+F11 in Excel and Word on Windows) and type code. This is needed for loops, conditions, and anything the recorder cannot capture.
- Import or receive a macro-enabled file: Files with extensions like .xlsm, .docm, or .pptm can contain macros written by someone else.
When you run a macro, the host application interprets the VBA line by line. The macro can read and write cells, paragraphs, slides, and mail items; call built-in functions; display dialog boxes; and interact with other Office applications through automation. Macros cannot run when the application is closed, and they run with the same permissions as your user account — which is why security matters.
Common Uses and a Worked Example
Typical macro tasks include reformatting imported data, generating recurring reports, applying consistent styles across documents, merging data from multiple sheets, and automating Outlook filing rules that go beyond the built-in rules wizard. A simple Excel example: you receive a monthly CSV export with dates stored as text and inconsistent capitalization. A recorded macro can select the date column, run Text to Columns, apply a date format, and apply PROPER to name columns — all in one keystroke. The recorded code might look like this:
Sub CleanExport()
Columns("A:A").TextToColumns Destination:=Range("A1"), DataType:=xlDelimited, Comma:=True
Columns("B:B").NumberFormat = "yyyy-mm-dd"
Columns("C:C").Value = Application.WorksheetFunction.Proper(Columns("C:C").Value)
End Sub
You would assign that macro to a button or a keyboard shortcut (Developer tab > Macros, or the shortcut recorder) so it runs with one click. In Word, a common macro inserts a standard header and footer block with the current date and document properties. In Outlook, a macro can pre-fill a reply template or move a message to a folder based on subject keywords.
Macro Security and the Trust Center
Macros are also a well-known malware delivery method because VBA can download files, modify documents, and access the file system. Microsoft therefore disables macros by default in files downloaded from the internet or received as email attachments. When you open such a file, a yellow message bar appears with a button to enable content. The relevant settings live in the Trust Center: File > Options > Trust Center > Trust Center Settings > Macro Settings (labels can differ slightly by version and platform). The standard options are:
- Disable all macros without notification — safest, but legitimate macros will not run.
- Disable all macros with notification — the default; you get the message bar and can enable per file.
- Disable all macros except digitally signed macros — only macros from trusted publishers run.
- Enable all macros — not recommended; it removes the main protection.
Only enable macros in files you trust or that come from a verified source. A digitally signed macro from a known publisher is safer than an unsigned one. If you are unsure, open the file with macros disabled and inspect the VBA code (Alt+F11) before enabling anything. On Mac, the path is similar but the Visual Basic Editor is available in Excel and Word; some automation features differ from Windows.
Macros vs. Other Automation Tools
Microsoft now offers several automation routes, and choosing the right one matters:
- VBA macros — best for in-app, repetitive tasks inside a single document or workbook; require macro-enabled file formats.
- Office Scripts — available in Excel for the web and some desktop versions; TypeScript-based and stored in the workbook, but not a full replacement for VBA.
- Power Automate — cloud flows that connect Microsoft 365 services and external apps; better for cross-app workflows and scheduled jobs.
- Quick Parts and AutoText — simple reusable content in Word, not programmable.
A common misconception is that macros are obsolete. They remain fully supported in desktop Office, and many organizations rely on them for legacy processes. However, files must be saved in a macro-enabled format (.xlsm, .docm, .pptm); saving as .xlsx or .docx strips the macros.
Common Problems and Fixes
- Macros are greyed out or missing: The file may be in a non-macro format, or the Developer tab is hidden. Enable the Developer tab in File > Options > Customize Ribbon.
- "Macros have been disabled" message bar: Click Enable Content only if you trust the file. If the bar does not appear, check Trust Center macro settings.
- Recorded macro does not repeat correctly: The recorder captures absolute cell references; edit the VBA to use relative references (Developer > Use Relative References before recording).
- Macro runs on one computer but not another: References to other workbooks, add-ins, or paths may be missing; check Tools > References in the Visual Basic Editor.
- File opens with macros removed: The file was saved in a non-macro format or blocked by policy; resave as .xlsm or .docm and check with your administrator.
Frequently Asked Questions
Are macros safe to enable?
Only if you trust the source. Macros can run harmful code, so Microsoft disables them by default in downloaded files. Enable content only for files you expect to contain macros and, when possible, verify the publisher's digital signature.
Can I use macros in Excel for the web?
No. Excel for the web does not run VBA macros. You can view and edit macro-enabled workbooks, but the macros execute only in the desktop app. Office Scripts are the web-based automation alternative.
What file extension do macro-enabled files use?
Excel uses .xlsm, Word uses .docm, and PowerPoint uses .pptm. The standard .xlsx, .docx, and .pptx formats cannot store VBA macros.
How do I see the code behind a macro?
Open the Visual Basic Editor with Alt+F11 (Windows) or via Tools > Macro > Visual Basic Editor (Mac, menu labels vary). Your macros appear in the Project Explorer under Modules or the document object.
Why does my macro disappear after saving?
You likely saved in a non-macro format. Use Save As and choose the macro-enabled format, then confirm the macro is still present under Developer > Macros.
Do macros work in Outlook?
Yes, Outlook supports VBA macros on Windows desktop. They are commonly used for custom rules and templates. Mac Outlook does not support VBA macros.