VBA & Macro Problems

Fix a Word for Mac Macro That Replaces Text Only After the Cursor

Amos GikundaAmos Gikunda Nov 22, 2026 868 views

Question details

Replace all matching text throughout a Word document rather than only after the cursor.

Fix a Word for Mac Macro That Replaces Text Only After the Cursor
Product
Microsoft Word for Mac 2016
Device & OS
Mac
Scenario
A user runs a recorded VBA find-and-replace macro on a Word document.
Observed behavior
The macro changes matching text only after the current cursor position.
Before you start

Identify the exact text to find and its replacement. Make sure macros are enabled for the document and that you can open the Visual Basic Editor.

Solution 1Recommended

Run Find and Replace on the Entire Document Range

Use the document's content range instead of the current selection so the search starts at the beginning of the main document.

The following macro searches the main document body. Headers, footers, and other separate story ranges require additional handling.

1
Open the Visual Basic Editor

In Word, open Tools > Macro > Visual Basic Editor, then open the module containing your macro or insert a new module.

2
Add the replacement macro

Paste this code into the module and replace the sample strings with your own text: Sub ReplaceThroughoutDocument() With ActiveDocument.Content.Find .ClearFormatting .Replacement.ClearFormatting .Text = "text to find" .Replacement.Text = "replacement text" .Forward = True .Wrap = wdFindStop .Execute Replace:=wdReplaceAll End With End Sub

3
Run the macro

Return to Word, open Tools > Macro > Macros, select ReplaceThroughoutDocument, and click Run.

4
Check the results

Review the document body to confirm that matches before and after the original cursor position were replaced. Save the file as a macro-enabled Word document (.docm) if you need to keep the macro in it.

Run Find and Replace on the Entire Document Range
Check search settings: If the results are unexpected, review options such as Match Case and Use Wildcards in Word's Find and Replace dialog; Find settings can affect the macro.
Free Microsoft Office alternative

Replace Text in Word Documents with WPS Writer

For everyday document editing, WPS Office is a free, lightweight alternative with a familiar interface. Open compatible Word files in WPS Writer and use Find and Replace for straightforward text changes as you transition between office suites.

Find and replace matching text in WPS WriterOpen and edit Microsoft Word DOC and DOCX filesUse a familiar interface for everyday document editingWork with a free, lightweight office suite
microsoft office alternative - wps office

Frequently Asked Questions

Why does my recorded macro start searching at the cursor?

A recorded macro may use Selection.Find, which operates from the current selection. Use ActiveDocument.Content.Find to search the main document body from its beginning.

Will this macro also replace text in headers and footers?

No. ActiveDocument.Content covers the main document body. To search headers and footers, extend the macro to process the relevant story ranges.

How do I keep the macro in my document?

Use File > Save As and choose the macro-enabled Word document format (.docm). A regular .docx file cannot retain VBA macros.

Can I replace text without using VBA?

Yes. In Word, open Edit > Find > Replace, enter the search and replacement text, and click Replace All.