How to Use Class ID in VBA CreateObject for Microsoft Word
Question details
The user wants to understand how to properly use the Class ID string with the VBA CreateObject function to automate Microsoft Word.

- Product
- VBA / Microsoft Word
- Device & OS
- not provided
- Scenario
- Writing a VBA macro to automate the creation and manipulation of Microsoft Word documents.
- Observed behavior
- The user needs the correct Class ID ('Word.Application') and clear steps to implement both early and late binding approaches to run the automation script successfully.
Ensure you have access to the Developer tab and the VBA Editor (ALT + F11) in your Office application before you begin writing or editing your macro code.
Use Late Binding with CreateObject
Late binding allows you to create a Word application instance without needing to configure external library references beforehand, making the code more compatible across different Office versions.
With late binding, you declare the application as a generic Object. This method uses the CreateObject function alongside the "Word.Application" Class ID string.
Press ALT + F11 to open the Visual Basic for Applications Editor, then click 'Insert' > 'Module' to create a new script.
Type 'Dim wdApp As Object' to declare a generic variable for the application.
Assign the Word Class ID to the variable by typing 'Set wdApp = CreateObject("Word.Application")'.
To see the Word window, add the line 'wdApp.Visible = True'. You can now use 'wdApp' to create documents and manipulate text.

Use Early Binding with Word Object Library
Early binding provides code autocomplete (IntelliSense) and better execution performance by explicitly referencing the Word Object Library.
Automate Documents with WPS Office VBA
WPS Office features an advanced, built-in VBA environment that supports macros and document automation. You can easily run, edit, and create VBA scripts directly within the application, ensuring high compatibility with your existing automation codes.
- 1. Open WPS Writer: Launch WPS Writer on your computer and open a new or existing document.
- 2. Access the Developer Tab: Navigate to the 'Tools' tab on the top ribbon and click on 'Developer' to access the macro tools.
- 3. Launch the VBA Editor: Click on 'VBA Editor' or press ALT + F11 to open the coding environment.
- 4. Run Your Automation Script: Insert a new module, paste your automation code, and run the macro to instantly create or modify your documents.

Frequently Asked Questions
What is a Class ID in VBA automation?
A Class ID (or class string) is a unique identifier used within functions like CreateObject to specify which external application or component you want to automate. For example, 'Word.Application' tells VBA to start an instance of Microsoft Word.
Why do I get an 'ActiveX component can't create object' error?
This error typically occurs if the application associated with the Class ID is not installed on the computer executing the code, or if there is a typographical error in the Class ID string, such as misspelling 'Word.Application'.
What is the difference between early and late binding in VBA?
Early binding requires you to manually reference the object library (Tools > References) to gain features like IntelliSense and slightly faster execution. Late binding uses CreateObject without requiring library references, making your script more flexible and independent of the user's specific application version.
Can I use CreateObject to automate Excel as well?
Yes, you can automate Microsoft Excel using the same method. You simply need to replace the Class ID with 'Excel.Application' inside the CreateObject function.




