How to Create a VBA Macro to Insert a Line in Word for Mac
Question details
The user wants to automate inserting a customized blue line using a keyboard shortcut or macro because the standard macro recorder does not capture shape insertions.

- Product
- Microsoft Word
- Device & OS
- Mac
- Scenario
- Attempting to quickly insert a specific line shape without repeatedly navigating the Insert menu, but the built-in macro recorder fails to capture the action.
- Observed behavior
- The macro recorder successfully records text actions but ignores actions involving inserting or modifying shapes, leaving the recorded macro empty.
Ensure that the Developer tab is enabled in your Word ribbon to access the Visual Basic Editor, and verify that your document is saved as a Macro-Enabled Document (.docm).
Write a Custom VBA Macro and Assign a Keyboard Shortcut
Use a brief VBA script to programmatically insert the line, which bypasses the macro recorder's limitations, and assign it to a shortcut for instant access.
The built-in Word macro recorder is optimized for text formatting and often fails to capture graphical actions like drawing or inserting shapes. Writing a simple VBA script directly in the Visual Basic Editor is the most reliable workaround.
Navigate to the Developer tab on the ribbon and click on 'Visual Basic', or press Option + F11 on your Mac keyboard to open the editor.
In the left-hand Project pane, right-click your document name, select 'Insert', and choose 'Module'. Paste the following code into the blank window: Sub AddAShape() ActiveDocument.Shapes.AddShape msoShapeLineInverse, 50, 50, 50, 50 End Sub.
Return to the main Word window. Go to Tools > Customize Keyboard from the top menu. Under the 'Categories' list, scroll down and select 'Macros'.
Select 'AddAShape' from the list of macros on the right. Click into the 'Press new keyboard shortcut' box, press your desired key combination (e.g., Command + Shift + L), click 'Assign', and then 'OK'.

Use WPS Writer for Advanced Document Editing
WPS Office provides highly intuitive tools for adding shapes, formatting graphics, and managing document layouts. With deep compatibility for Word formats and support for VBA in advanced versions, formatting your documents is seamless.
- 1. Launch WPS Writer: Open WPS Office and create a new document or open your existing file.
- 2. Insert Shapes Manually: Go to the Insert tab, click on 'Shapes', and select the line tool to easily draw and style your customized line.
- 3. Utilize Macro Automation: If you are using a version of WPS Office with VBA support, navigate to the Developer tab, click 'VBA Editor', and use standard VBA syntax to automate shape insertion.

Frequently Asked Questions
Why doesn't the macro recorder capture inserting shapes in Word?
The built-in macro recorder in Word is primarily designed to capture text input and basic formatting commands. It typically ignores mouse movements related to drawing, positioning, or modifying graphics and shapes.
How do I change the color of the inserted line to blue using VBA?
You can modify the macro to set the line color by assigning the shape to a variable. Adding a line of code like 'YourShape.Line.ForeColor.RGB = RGB(0, 0, 255)' will change the newly created line to blue.
Can I add my VBA macro to the Quick Access Toolbar instead of using a keyboard shortcut?
Yes. Go to Word Preferences > Ribbon & Toolbar, select the Quick Access Toolbar tab, choose 'Macros' from the 'Choose commands from' drop-down menu, select your macro, and move it to the toolbar for one-click access.




