The code itself works just fine in macOS 11.6.8, and 12.5.1. However, the first time you run the Automator application it will prompt you three times for permissions that you must grant in order for it to proceed. When you agree (select OK) each time, it will update the System Preferences > Security & Privacy > Privacy panel entries to make these permissions permanent. In this case, my arbitrary name for the Automator application is PagesXWord.app.
I exported a 180pp Pages document this morning to Word .docx without issues using this code.
First:

Second:

and finally:

As mentioned previously, the Automator Application requires two actions:
- Ask For Finder Items
- Start at Desktop
- Type: Folders ☑︎ Allow Multiple Selection
- Select the Pages folder, press the ⌘-key, and then select the output folder for the exported Word docx
- Run AppleScript
- Remove all default boilerplate content from this action and replace it with the AppleScript in the original post.
- The on quit handler should read: on quit and not on quit {}.
Here is the updated comment section for that AppleScript:
(*
The script converts Pages documents found in the source folder to Word (.docx) documents
in the output folder.
Intended to be used in an Automator application's Run AppleScript action
Preceded by an Ask for Finder Items action whose type is Folders with Allow Multiple
Selection, one chooses the folder containing the Pages documents and
then presses the ⌘+key to select the destination folder. This order is critical.
Reference: https://discussions.apple.com/thread/253072302
Tested: macOS 11.5.2 (20G95), Pages 11.1, macOS 10.14.6 (18G9323, Pages 10.1
Tested Update 2022-09-10: macOS 11.6.8, 12.5.1, Pages 12.1
VikingOSX, 2021-08-23, Apple Support Communities, No warranties/support expressed or implied.
*)
Hopefully, there are no English<->Italian namespace issues for quoted names as AppleScript is not auto-language sensing.
As Pages is no Word clone, the content of your existing Pages documents may not appear in Word format as it does in Pages. It might be better to achieve a visually faithful export to PDF, and then use MS Word v16.31 or later to open those PDFs and create Word .docx documents from them.