How to Randomize Pages in a Word Document for Tests
Question details
The user wants to automatically rearrange the pages of a document into a random order to create multiple unique test versions for students.

- Product
- Word Processor
- Device & OS
- not provided
- Scenario
- A teacher or instructor has a document with one exercise per page and needs to generate several randomized copies of the test.
- Observed behavior
- Instead of manually moving pages around, an automated method is needed to quickly shuffle the page sequence and output individual student files.
Ensure your document is properly formatted with hard page breaks (Ctrl + Enter) between each exercise. Save a backup copy of your original document before running any scripts or macros.
Use a VBA Macro to Randomize and Export Pages
Running a custom VBA script is the most efficient way to automatically randomize document pages and save multiple unique copies.
This method involves using a VBA macro that leverages the 'Rnd' function. The script will open your source document, generate a random sequence, extract the pages based on that sequence, and compile them into a new document for each student.
Press 'Alt + F11' on your keyboard to open the Visual Basic for Applications (VBA) window.
In the VBA editor, click on 'Insert' in the top menu bar, then select 'Module' to open a blank coding window.
Paste your page randomizer script into the module. Ensure the code is set to select page ranges rather than default line text.
Modify the source and destination folder paths within the macro code so it knows where to pull the original file and where to save the generated test versions.
Press 'F5' or click the 'Run' button on the toolbar to execute the script and generate your randomized test files.

Automate Tasks Efficiently with WPS Writer
WPS Office Writer provides an intuitive and powerful environment for handling complex document layouts. With robust tools and macro support in its professional versions, automating tasks like randomizing test pages is highly efficient.
- 1. Open Your Document: Launch WPS Writer and open the test document you wish to randomize.
- 2. Access Developer Tools: Navigate to the 'Developer' tab on the ribbon to access advanced document controls.
- 3. Open the VBA Editor: Click on 'Macros' or the VBA Editor icon to input your randomization script.
- 4. Run and Save: Execute the script directly within WPS to output the randomly sequenced test pages into your specified folder.

Frequently Asked Questions
Can I randomize specific paragraphs instead of whole pages?
Yes. If your test relies on questions rather than full pages, you can adjust the VBA macro to select paragraph ranges instead of page ranges before randomizing and pasting them into the target document.
Is there a way to randomize pages without using a macro?
Without a macro or a specialized third-party tool, Word processors do not have a built-in 'shuffle pages' button. You would have to manually cut and paste pages to rearrange them.
Why is my macro skipping some exercises?
This usually happens if your document relies on natural text wrapping instead of hard page breaks. Ensure you insert a manual page break (Ctrl + Enter) at the end of each exercise so the macro can accurately identify the page boundaries.




