How to Apply Columns to Selected Text Only Using Word VBA
Question details
The user needs to format a specific selection of text into multiple columns using a VBA macro without affecting the rest of the document.

- Product
- Word
- Device & OS
- not provided
- Scenario
- Automating page layout formatting where only a highlighted block of text is converted into a multi-column layout.
- Observed behavior
- Because Word applies column settings at the section level rather than the text level, applying columns directly to arbitrary text fails unless continuous section breaks are dynamically inserted around the selection first.
Ensure you have the Developer tab enabled in your word processor to access the VBA editor, and remember to save your document as a Macro-Enabled Document (.docm) to preserve your scripts.
Use a VBA Macro to Insert Section Breaks and Apply Columns
This macro automates the process of isolating the selected text with continuous section breaks and applying a two-column layout to that newly created section.
To format only a highlighted portion of text, a VBA macro must simulate what the graphical interface does behind the scenes: it inserts continuous section breaks immediately before and after the selected range. Once the text is isolated into its own section, the TextColumns property can be modified without altering the layout of the preceding or subsequent text.
Press ALT + F11 on your keyboard to open the Visual Basic for Applications (VBA) editor in your word processor.
In the left-hand Project Explorer pane, right-click your document's name, navigate to 'Insert', and select 'Module' to create a new blank script window.
Copy and paste the following code into the module window: Sub TwoColumns() ActiveDocument.Range(Start:=Selection.Start, End:=Selection.Start).InsertBreak Type:=wdSectionBreakContinuous Selection.Start = Selection.Start + 1 ActiveDocument.Range(Start:=Selection.End, End:=Selection.End).InsertBreak Type:=wdSectionBreakContinuous With Selection.PageSetup.TextColumns .SetCount NumColumns:=2 .EvenlySpaced = True .LineBetween = False End With End Sub
Close the VBA editor. Highlight the specific text in your document that you want to format into columns. Then, press ALT + F8, select 'TwoColumns' from the macro list, and click 'Run'.
Easily Format Selected Text into Columns via UI
While VBA provides excellent automation, WPS Writer allows you to apply column formatting directly to selected text through an intuitive user interface. It automatically handles the background task of inserting continuous section breaks for you.
- 1. Select the Target Text: Use your mouse or keyboard to highlight the specific block of text you want to format into columns.
- 2. Navigate to Page Layout: Click on the 'Page Layout' tab located in the top menu ribbon.
- 3. Choose the Number of Columns: Click the 'Columns' drop-down button and select 'Two', 'Three', or 'More Columns' to apply the formatting instantly.
- 4. Adjust Settings (Optional): If you selected 'More Columns', you can fine-tune the column widths, adjust spacing, and choose whether to add a line between the columns.

Frequently Asked Questions
Why does my entire document change when I apply columns?
By default, word processors apply column formatting to the entire document or the current section. If you haven't inserted continuous section breaks to isolate your text, the new column setting will naturally affect everything.
How do I ensure my VBA macro is saved for future use?
You must save your file as a Macro-Enabled Document (.docm). If you save it as a standard .docx file, your word processor will strip out the VBA code for security reasons, and your macro will be lost.
Can I set a specific width for the columns using this VBA macro?
Yes. Inside the 'With Selection.PageSetup.TextColumns' block, you can add properties like '.Width = CentimetersToPoints(11.36)' and '.Spacing = CentimetersToPoints(1.27)' to precisely define your column dimensions instead of relying on '.EvenlySpaced = True'.




