Microsoft Word doesn't understand the "save as" message

I have a script which is saving an Word document as an PDF, and it always worked. Not sure when the last time it was ran, but now I get this error:

Microsoft Word kreeg een fout: document "name.docx" begrijpt het bericht 'save as' niet

This translates to:

Microsoft Word got an error: document "name.docx" does not understand the message 'save as'

I reproduced this with an open Word document and this script:

set rapport_name to "doc.docx"
set pdf_file to "/Users/doekman/Downloads/doc.pdf"
tell application "Microsoft Word"
	tell active document
		save as document rapport_name file name pdf_file file format format PDF
	end tell
end tell

Before running the script, I opened the “doc.docx” document manually to simplify the test case. It doesn’t matter if the document contains unsaved changes or not.

As said, this always worked. I remembered I had a lot of trouble finding a way to save a docx to pdf. Any help here? Am I doing something weird? Or is there an other way of doing this? The script runs on different machines, so I can’t install custom software.

If the document you want to export is the frontmost, you don’t need to give its name:

set pdf_file to "/Users/doekman/Downloads/doc.pdf"
tell application "Microsoft Word"
	save as active document file name pdf_file file format format PDF
end tell

But maybe your problem is an access authorization issue.
Try to save your test doc in another folder and see if Word asks for access in this folder.

@doekman
You could try this…

set savePath to POSIX path of (path to downloads folder) & "doc.pdf"
tell application "Microsoft Word"
	save as document (its name of front document) file name savePath file format format PDF
end tell

I find Word to be very fussy about syntax. Here is my handler for saving the current Word document in PDF format. Feel free to adapt this to your needs:

on saveAsPDF(theFilename)
	tell application "Microsoft Word"
		set filePath to path of front document
	end tell
	tell application "System Events" to set parentFolder to path of (container of disk item filePath)
	
	set theFilename to filePath & ":" & theFilename & ".pdf"
	
	tell application "Microsoft Word"
		set theActiveDoc to the active document
		save as theActiveDoc file format format PDF file name theFilename
	end tell
	return theFilename
end saveAsPDF