How to Use Excel VBA to Control Word Cursor Movement
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.

- 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.
Ensure you have saved your current Excel workbook containing the VBA code to prevent any data loss during macro execution or debugging.
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.
Press Alt + F11 in Microsoft Excel to open the Visual Basic for Applications editor.
Find the module or subroutine where you have written the code to automate the Word cursor.
Change any references of wdStory to the number 6. For example, modify your code to read: objSelection.HomeKey Unit:=6
Change references of wdCharacter to 1. For instance, to move the cursor to the right, use: objSelection.MoveRight Unit:=1, Count:=5
Run the macro again to verify that the Word cursor now moves precisely as intended without throwing unrecognized constant errors.

Enable the Microsoft Word Object Library Reference
Add the Word Object Library reference to your Excel VBA project to allow it to recognize named constants like wdStory natively.
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. Download the software: Visit the official WPS Office website to download the free installation package for your operating system.
- 2. Install WPS Office: Run the installer and follow the quick on-screen instructions to set up WPS Office on your device.
- 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.

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.




