Practical Macro Examples
Practical Macro Examples
Practical Macro Recipes & VBA Automation
Behind every recorded macro in Microsoft Word is Visual Basic for Applications (VBA) code. Pressing Alt + F11 opens the VBA Integrated Development Environment (IDE), allowing you to inspect, fine-tune, and supercharge your macros.
Recipe 1: The "Clean Pasted Web Text" Macro
When text is pasted from websites, it often contains unwanted formatting, hyperlinks, double spaces, and grey background fills. This macro strips everything and standardizes the text in one click:
Recipe 2: The "Corporate Footer Stamp" Macro
Automatically injects the standard corporate footer with file path, date, and page numbers across all sections:
Recipe 3: The 1-Click "Export Clean PDF" Macro
Exports the active document as a high-resolution PDF in the same folder with the same file name, without going through Export menus:
How to Paste VBA Code into Word
- 1Press Alt + F11 to open the VBA Editor.
- 2In the Project Explorer on the left, double-click Normal > Modules > NewMacros.
- 3Paste the code at the bottom of the window.
- 4Press Ctrl + S to save. Close the editor.
- 5The macro is now ready to run from your Macros dialog or custom button!
Multiple Choice Questions
1. What is the keyboard shortcut to launch the Visual Basic for Applications (VBA) Editor in MS Word?
A. Alt + F1 B. Alt + F11 C. Ctrl + F11 D. Shift + F9 Answer: B Explanation: Alt + F11 is the universal keyboard shortcut to open the VBA editor in all Office applications.
2. In VBA code, which object represents the currently selected text on the document canvas?
A. ActiveSheet B. Selection C. RangeText D. CurrentLine Answer: B Explanation: Selection represents the active text cursor or highlighted block in Word VBA.
3. What programming language underlies recorded macros in Microsoft Office applications?
A. JavaScript B. Python C. Visual Basic for Applications (VBA) D. C++ Answer: C Explanation: VBA (Visual Basic for Applications) is the internal automation programming language of MS Office.
4. In the VBA Project window, which module store ensures code runs across all documents on your system?
A. Project.docx B. Normal > Modules > NewMacros C. System32 D. ThisDocument Answer: B Explanation: Placing macros in Normal > Modules > NewMacros makes them available globally across all Word files.
5. What VBA method exports an active Word document into a standard PDF file programmatically?
A. Document.PrintToPDF B. ActiveDocument.ExportAsFixedFormat C. Document.ConvertToPDF D. SaveAsPDF() Answer: B Explanation: ActiveDocument.ExportAsFixedFormat is the native VBA method for publishing to PDF format.
Creating & Using Templates
Continue learning with hands-on practice, examples, and exercises in the upcoming topic.
Related Lessons
| Previous Lesson | Next Lesson |
|---|---|
| Assigning Macros to Buttons | Creating & Using Templates |
Practice Quiz
Test your understanding of this lesson with 5 questions. Each question has one correct answer.