VBA & Macro Problems

How to Use Excel VBA to Control Word Cursor Movement

Algirdas JasaitisAlgirdas Jasaitis Nov 4, 2026 869 views

Question details

The user needs to control the Microsoft Word cursor using Excel VBA, but encounters errors because standard Word constants like wdStory and wdCharacter are not recognized by Excel.

How to Control Word Cursor Movement from Excel VBA
Product
Microsoft Excel and Word
Device & OS
not provided
Scenario
Automating Microsoft Word documents and moving the text cursor programmatically via macros written inside Microsoft Excel.
Observed behavior
Excel VBA fails to recognize standard Word constants, causing the code to either throw a compilation error or fail to move the cursor correctly.
Before you start

Ensure you have saved your current Excel workbook containing the VBA code to prevent any data loss during macro execution or debugging.

Solution 1Recommended

Use Numeric Values Instead of Word Constants

Replace named Word constants with their equivalent numeric values to bypass the need for external library references when using Late Binding in Excel VBA.

When Excel automates Word using Late Binding, it does not inherently know the values of Word-specific constants. By supplying the direct numeric equivalents, your macro can execute flawlessly without additional setup.

1
Open the VBA Editor

Press Alt + F11 in Microsoft Excel to open the Visual Basic for Applications editor.

2
Locate the cursor movement script

Find the module or subroutine where you have written the code to automate the Word cursor.

3
Replace wdStory with 6

Change any references of wdStory to the number 6. For example, modify your code to read: objSelection.HomeKey Unit:=6

4
Replace wdCharacter with 1

Change references of wdCharacter to 1. For instance, to move the cursor to the right, use: objSelection.MoveRight Unit:=1, Count:=5

5
Test your macro

Run the macro again to verify that the Word cursor now moves precisely as intended without throwing unrecognized constant errors.

Use Numeric Values Instead of Word Constants
Late Binding Best Practice: Using numeric equivalents makes your VBA code more portable, as it will run on other computers without requiring users to manually configure library references.
Free Microsoft Office alternative

Try WPS Office for Seamless Macro Compatibility

If you frequently work with macros and cross-application automation, consider switching to WPS Office. It provides an excellent, free alternative to Microsoft Office with robust built-in VBA support, lightweight performance, and an interface that feels instantly familiar.

  1. 1. Download the software: Visit the official WPS Office website to download the free installation package for your operating system.
  2. 2. Install WPS Office: Run the installer and follow the quick on-screen instructions to set up WPS Office on your device.
  3. 3. Open your macro files: Open your existing .xlsm or .docm files directly in WPS Office to continue writing and executing your VBA code seamlessly.
Fully compatible with Microsoft Excel (.xlsx, .xlsm) and Word (.docx) file formats.Advanced built-in VBA editor to smoothly run, edit, and create your macros.Lightweight design ensures incredibly fast loading times even with heavy macro workbooks.Clean, familiar user interface makes transitioning easy with zero learning curve.
microsoft office alternative - wps office

Frequently Asked Questions

Why does Excel VBA return an error when using wdStory?

When using Late Binding to automate Word from Excel, the VBA editor does not load Word's specific object libraries by default. Because of this, named constants unique to Word, like wdStory, are completely unrecognized by Excel and cause compilation or runtime errors.

How do I find the numeric values for other Word VBA constants?

You can find the numeric value of any Word constant by opening the VBA editor inside Microsoft Word, launching the Immediate Window by pressing Ctrl + G, typing a question mark followed by the constant name (e.g., ?wdLine), and pressing Enter. The numeric equivalent will be printed on the next line.

What is the difference between Early Binding and Late Binding in VBA?

Early Binding requires you to check a reference to an external object library (like Word) in the Tools menu, which allows IntelliSense and named constants to work. Late Binding creates the object at runtime using CreateObject without a pre-set reference, forcing you to use numeric constants instead of named ones, but offering better cross-version compatibility.