How to Apply Multilevel Numbering to a Word Bookmark Using VBA
Question details
The user needs to use VBA to apply multilevel list formatting to text contained within a specific bookmark.

- Product
- Word
- Device & OS
- not provided
- Scenario
- Automating document formatting by applying multilevel numbering to specific bookmarked sections via VBA macros.
- Observed behavior
- Standard VBA list formatting fails because Bookmark objects do not expose the ListFormat property directly. It must be applied using Range objects and preferably linked to paragraph styles.
Before running the macro, ensure that you have set up a multilevel list in your document and linked each numbering level to a unique paragraph style.
Apply Multilevel Numbering Using Range and Paragraph Styles
The most reliable method is linking numbering levels to unique paragraph styles and applying these styles to the paragraphs inside the bookmark's range.
Because the Bookmark object does not directly support the ListFormat property, you must reference the bookmark's Range object instead.
Rather than applying hardcoded list formatting directly via VBA, the best practice is to create unique paragraph styles for each list level and loop through the target paragraphs within the bookmark to apply those styles based on your formatting rules.
In your Word document, create a multilevel list. Link each level of the list to a specific paragraph style (e.g., 'ListLevel1', 'ListLevel2').
Press Alt + F11 to open the Visual Basic for Applications editor, and insert a new Module.
In your macro, assign the target bookmark to a Range object using code like: Set rng = ActiveDocument.Bookmarks("YourBookmarkName").Range
Create a For Each loop to iterate through the paragraphs in the range: For Each para In rng.Paragraphs
Within the loop, use an If or Select Case statement to evaluate each paragraph (e.g., checking indent size) and apply the correct style: para.Style = "ListLevel1"

Apply ListFormat Directly to the Bookmark Range
If you prefer not to use custom paragraph styles, you can apply a ListTemplate directly to the Bookmark's Range object.
Automate Document Formatting with WPS Writer Macros
WPS Writer provides robust Macro and VBA support in its advanced versions, allowing you to seamlessly execute automation scripts, such as applying multilevel numbering to bookmarks, exactly as you would in other major word processors.
- 1. Enable Macros: Open WPS Writer, navigate to the 'Developer' tab on the ribbon, and click 'Macros' to access the macro environment.
- 2. Insert the VBA Code: Click 'Visual Basic' to launch the editor, insert a new module from the project window, and paste your bookmark numbering code.
- 3. Run the Macro: Close the editor and execute the script from the Macros menu to automatically apply your multilevel paragraph styles to the specified bookmark range.

Frequently Asked Questions
Why do I get an error when using ListFormat on a Bookmark object in VBA?
The ListFormat property applies only to Range or Selection objects, not directly to Bookmark objects. To fix this, append .Range to your bookmark object reference (e.g., ActiveDocument.Bookmarks("MyBookmark").Range.ListFormat).
How can my VBA macro determine which list level to apply to each paragraph?
VBA needs specific logical criteria to determine the appropriate list level. A common programmatic approach is to check the LeftIndent property of each paragraph or parse specific text characters, and then apply the corresponding paragraph style for that designated level.
Is it better to use paragraph styles or ApplyListTemplate for multilevel lists?
Using unique paragraph styles linked to a multilevel list is highly recommended. It is significantly more stable, easier for users to manage manually later, and less prone to document corruption or numbering glitches compared to applying list templates directly via VBA.




