Sorry, missed this, and it doesn’t look line anyone else has picked up in the interim. Make sure yoiu put triple back rticks aroiund your code to mark it as a code block - that’s why your code currently looks to be mixed with non-code.
The export I would expect is coming from the line, and while that also looks a bit crazy to me (multiple ‘format’ occurrences), it appears to be valid judging by what else I have seen online. I’m afraid I can’t validate it as I don’t have Word on my Mac or subscribe to Office 365 - thoiugh I am a daily user on my Windows PC at the day job.
save as theActiveDoc file format format PDF file name theFilename
What happens if you comment out that line and the close line; as in can you manually save as PDF at that point?
Also check that the file path is valid and that if you hard code the same file path in place of the file name that it works. I’m assuming the setting of the default path is so that you can just get away with the file name in the save as PDF line.