Converting Excel to PDF Via AppleScript

Hello,

I would like to open a folder full of Excel spreadsheets, one by one, to save each as a PDF and close it. I’m having trouble locating the right syntax for the core operation and for iterating through the folder. I have two questions therefore:

  1. What is the proper syntax for “save workbook as MainWkbk filename fName file format PDF”?
  2. How do I iterate?

Thank you to anyone who can help a new AppleScripter (but not a newcomer to coding). My code:

set textToDisplay to “How many files are in this folder?”
display dialog textToDisplay default answer “3”
set valueEntered to text returned of the result
try
set valueEntered to valueEntered as integer
end try
if class of valueEntered is integer then
repeat valueEntered times
tell application “Finder”
set OpenFolder to choose folder
set OpenFile to open first file in OpenFolder
tell application “Microsoft Excel”
set MainWkbk to active workbook
set fName to string value of MainWkbk & “.pdf”
save workbook as MainWkbk filename fName
close MainWkbk
activate application “Finder”
end tell
end tell
end repeat
else
display dialog “You did not enter a (valid) number.”
end if

FIgured them both out, through a bunch of trial and error. In case anybody is interested:

activate application "Microsoft Excel"
set Inc to 0
repeat 10 times
	tell application "Microsoft Excel"
		set Inc to Inc + 1
		set MainWkbk to workbook Inc
		try
			activate object worksheet "Sheet1" of MainWkbk
			set fName to string value of range "D1" & " " & string value of range "D3" & " " & string value of range "D4" & ".pdf"
			save workbook as MainWkbk filename fName file format PDF file format
		end try
	end tell
end repeat