You can make a difference in the Apple Support Community!

When you sign up with your Apple Account, you can provide valuable feedback to other community members by upvoting helpful replies and User Tips.

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Use Automator to save to PDF Office 365 Excel documents

Hi,


I saw this Apple Script to convert Word documents to PDF: Use Automator to save to PDF Office 365 W… - Apple Community


Is there any chance to use some similar script to convert Excel (xlsx, xls) documents?


Tried some things but didn't work.


If some one can help, I appreciate.


Thank you.



Posted on Jan 20, 2023 6:32 AM

Reply
Question marked as Top-ranking reply

Posted on Jan 20, 2023 9:41 AM

AppleScripting Office applications is a black art.


That said, the changes you need are fairly trivial. The clues are in the dictionary for the respective apps.


This is the block in the original (Word) script.


	tell application id "com.microsoft.Word"
		activate
		repeat with i from 1 to count of selected_files
			open (item i of selected_files)
			set theOutputPath to (item i of outPDF)
			-- close access (open for access exportDocument)
			tell active document
				save as it file name theOutputPath file format format PDF
				close saving no
			end tell
		end repeat
	end tell


This is the equivalent for Excel:


	tell application id "com.microsoft.Excel"
		activate
		repeat with i from 1 to count of selected_files
			open (item i of selected_files)
			set theOutputPath to (item i of outPDF)
			tell sheet 1 of active workbook
				save as it filename theOutputPath file format PDF file format
				close saving no
			end tell
		end repeat
	end tell


Why Microsoft can't standardize across their Office apps, I don't know.

6 replies
Question marked as Top-ranking reply

Jan 20, 2023 9:41 AM in response to venturosaum2

AppleScripting Office applications is a black art.


That said, the changes you need are fairly trivial. The clues are in the dictionary for the respective apps.


This is the block in the original (Word) script.


	tell application id "com.microsoft.Word"
		activate
		repeat with i from 1 to count of selected_files
			open (item i of selected_files)
			set theOutputPath to (item i of outPDF)
			-- close access (open for access exportDocument)
			tell active document
				save as it file name theOutputPath file format format PDF
				close saving no
			end tell
		end repeat
	end tell


This is the equivalent for Excel:


	tell application id "com.microsoft.Excel"
		activate
		repeat with i from 1 to count of selected_files
			open (item i of selected_files)
			set theOutputPath to (item i of outPDF)
			tell sheet 1 of active workbook
				save as it filename theOutputPath file format PDF file format
				close saving no
			end tell
		end repeat
	end tell


Why Microsoft can't standardize across their Office apps, I don't know.

Jan 20, 2023 6:58 AM in response to venturosaum2

I have never written any AppleScript to save content from Microsoft applications to PDF.


I recommend that you continue searching on the web (e.g. MacScripter) to see if someone has done this using AppleScript. I also recommend that you look at the dates the articles were posted as you want examples from 2020 or later to ensure you have current Microsoft Excel AppleScript dictionary syntax, and not that from Office 2011 or even 2016.

Feb 23, 2023 2:02 AM in response to Camelot

Quite new to the AppleScript, running the above script on a Word file; Office 365, Norwegian language. The response was (translated from Norwegian): "Microsoft Word got an error: active document do not understand the message "save as". (-1708)"

Save as is Lagre som in Norwegian, so I changes save as to lagre som in the script

Compiled and the response from the script was pop-up window "syntax error, expected end of line, but found identification" (translated from Norwegian)


Any ideas how to solve?


Use Automator to save to PDF Office 365 Excel documents

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.