I had a Hazel action, monitoring a folder, that would automatically convert Word to PDF files. To accomplish this, Hazel was executing an AppleScript. This has been well documented, but now since upgrading to Monterey, Word will open, but then fail to export the document with an error. Is there a new setting with Monterey?
tell application “Microsoft Word” to activate
delay 1
tell application “Microsoft Word” to set theOldDefaultPath to get default file path file path type documents path – looks like we change the default path to where the document is and then set it back when we’re done
try
tell application “Finder”
set theFilePath to container of theFile as text
set ext to name extension of theFile
set theName to name of theFile
copy length of theName to l
copy length of ext to exl
set n to l - exl - 1
copy characters 1 through n of theName as string to theFilename
set theFilename to theFilename & ".pdf"
tell application "Microsoft Word"
set default file path file path type documents path path theFilePath
open theFile
set theActiveDoc to the active document
save as theActiveDoc file format format PDF file name theFilename
close theActiveDoc
end tell
end tell
end try
try
tell application "Microsoft Word" to set default file path file path type documents path path theOldDefaultPath
end try
Microsoft Word error is that the “export is not available”
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.