AppleScript: quarkxpress export all layouts as pdf

set TargetFolder to choose folder with prompt "Please choose the folder where to save the PDFs"
tell application "QuarkXPress"
    set MyProject to object reference of project 1
    tell MyProject
        repeat with i from 1 to count of layout space
            try
                export layout space i as "PDF" in ((TargetFolder as string) & name of layout space i & ".pdf")
            on error errMsg number errNum
            end try
        end repeat
    end tell
end tell