VBA & Macro Problems

How to Create a VBA Macro to Insert a Line in Word for Mac

John WilsonJohn Wilson Nov 2, 2026 868 views

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.

Create a VBA Macro Shortcut to Insert a Line in Word for Mac
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.
Before you start

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).

Solution 1Recommended

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.

1
Open the Visual Basic Editor

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.

2
Insert the Macro Code

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.

3
Assign a Keyboard Shortcut

Return to the main Word window. Go to Tools > Customize Keyboard from the top menu. Under the 'Categories' list, scroll down and select 'Macros'.

4
Map the Shortcut Key

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'.

Write a Custom VBA Macro and Assign a Keyboard Shortcut
Customization Tip: You can modify the numerical values (50, 50, 50, 50) in the VBA code to adjust the horizontal position, vertical position, width, and height of your line.
Efficient Document Formatting

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. 1. Launch WPS Writer: Open WPS Office and create a new document or open your existing file.
  2. 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. 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.
Fully compatible with Microsoft Word formats (.docx, .docm)Intuitive graphic and shape insertion toolsLightweight installation and fast performance on both Mac and Windows
microsoft office alternative - wps office

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.