Powerpoint Create File Extension an Save as .PPTX and .PDF

Hi all,

I currently have following problem. I want to save a currently active .pptx presentation with a dedicated automatically created file name first as a .pptx and then with the same filename as a .pdf.

Therefore I have amended an existing script to my needs. It runs through smoothly (I can also see the progress bar for the pdf) but If I’m looking into the folder there is no file. Additionally weird is, that if I’m running it the ppt would suddenly start to PRINT on my printer?!?!

Could anybody possibly point me to the answer?

Thank you very much,
Phil


on savePPT()
	-- Create a new document and save it into the Documents folder
	
	-- generate the default file name
	set todaysDate to (current date)
	set fullName to the text returned of (display dialog "Enter Full Name" with title "Master PPT Query" default answer "")
	set the nameToUse to ¬
		("Company Presentation - " & fullName & " " & (month of todaysDate) as string) & ¬
		space & (year of todaysDate) as string
	--> "Monthly Report - December 2014"
	
	-- make sure the file name is not in use
	set the destinationFolderHFSPath to "/Users/(....)/40_Pitches" as string
	repeat with i from 0 to 100000
		if i is 0 then
			set incrementText to ""
		else
			set incrementText to "-" & (i as string)
		end if
		set thisFileName to nameToUse & incrementText & ".pptx"
		set thisFilePath to destinationFolderHFSPath & thisFileName
		tell application "Finder"
			if not (exists document file thisFilePath) then exit repeat
		end tell
	end repeat
	
	tell application "Microsoft PowerPoint"
		activate
		-- create a new document and store its reference in a variable
		set thisDocument to active presentation
		-- save the document
		save thisDocument in file thisFilePath
		save thisDocument in destinationFolderHFSPath as save as PDF
	end tell
end savePPT

You pass to the Finder the path to a folder in a variable named : destinationFolderHFSPath but this one contains a POSIX path : “/Users/(…)/40_Pitches” as string

Replacing :

set the destinationFolderHFSPath to "/Users/(....)/40_Pitches" as string

by

set destinationFolderPOSIXPath to "/Users/(....)/40_Pitches" as string
set destinationFolderHFSPath to (POSIX file destinationFolderPOSIXPath) as text

may help.

Yvan KOENIG running Sierra 10.12.5 in French (VALLAURIS, France) mardi 11 juillet 2017 15:08:58

Thank you very much Ivan! I have replaced my code with yours but still have the same Issue. It runs through smoothly, doesn’t create any error but also doesn’t create the files. Instead it obviously saves the original masterfile…

Any further thoughts on this?

OK. If I understand well you reach this block of instructions

The first save instruction seems to be OK.
I assume that the second one must be edited as:

save thisDocument in file (destinationFolderHFSPath &nameToUse & incrementText & ".PDF") as PDF

or maybe

save as thisDocument filename (destinationFolderHFSPath &nameToUse & incrementText & ".PDF") file format "PDF file format"

If it’s not sufficient try:


set pdfPath to (destinationFolderHFSPath &nameToUse & incrementText & ".PDF")
close access (open for read file thisFilePath)
close access (open for read file pdfPath)

	tell application "Microsoft PowerPoint"
		activate
		-- create a new document and store its reference in a variable
		set thisDocument to active presentation
		-- save the document
		save thisDocument in file thisFilePath
		save thisDocument in file pdfPath as PDF
		# or
		# save as thisDocument filename pdfPath file format "PDF file format"
	end tell


Don’t forget that Merdosoft products aren’t allowed to enter my home :confused:

Yvan KOENIG running Sierra 10.12.5 in French (VALLAURIS, France) mardi 11 juillet 2017 16:14:25

Thanks Ivan!

strangely enough even the first “save” does not work… it only would save the existing master presentation without giving it a new name via “save as”…

for the second I tried all given options. As it seems at least the syntax of my first version seems to be ok as in this script it’s attested to have worked all fine…

Mhmmm, still a lot of question marks…


on run argv
    set inputPath  to "/Users/myname/test.pptx"
    set outputPath to "/Users/myname/test.pdf"
    tell application "Microsoft PowerPoint"
        activate
        open inputPath
        save active presentation in outputPath as save as PDF
        close active presentation
        quit
    end tell
    return "finished"
end run

Oops, I used a wrong syntax for the close access. instructions.
Try to use:


set pdfPath to (destinationFolderHFSPath &nameToUse & incrementText & ".PDF")
close access (open for access file thisFilePath with write permission)
close access (open for access file pdfPath with write permission)

	tell application "Microsoft PowerPoint"
		activate
		-- create a new document and store its reference in a variable
		set thisDocument to active presentation
		-- save the document
		save thisDocument in file thisFilePath
		save thisDocument in file pdfPath as PDF file format
	end tell

Please, take care that since 1943/12/31, my first name is Yvan (not Ivan) :wink:

Yvan KOENIG running Sierra 10.12.5 in French (VALLAURIS, France) mardi 11 juillet 2017 17:54:45

Hi Yvan (my sincere apologies! ;)),

Thx very much for your efforts. We are already very close. The script does create a pptx and a pdf file with the correct file names in the correct folder. But strangely the files have 0 Byte and the Master Presentation still saves although it shouldn’t…

As it looks to me I still face some sort of issue that the presentation doesn’t get properly activated…

Any thoughts on this ?

Thx a million,
Phil

What you get are the files created by the instructions :

close access (open for access file thisFilePath with write permission)
close access (open for access file pdfPath with write permission)

They are supposed to solve a problem with sandboxing which is described elsewhere.
In your case it seems that the problem is not this one - or that there is an other problem + this one.

I will try to get a trial version of PowerPoint to see what is available in its AppleScript dictionary.

I don’t understand why I may enter macScripter with Firefox Safari Technology Preview but get the message “There has been an error” when I try to enter with the “standard” Safari Version 10.1.1 (12603.2.4).

Yvan KOENIG running Sierra 10.12.5 in French (VALLAURIS, France) mercredi 12 juillet 2017 12:07:04

Great, thx for your efforts! This highly appreciated.

So Merdosoft finally makes access to your home at least for a few hours… :smiley:

I was ready to violate my rules to try to help you but when I saw that the trial version is linked to a one month free subscription to Office 365, I rejected the project.

Yvan KOENIG running Sierra 10.12.5 in French (VALLAURIS, France) mercredi 12 juillet 2017 15:11:49

Hi Yvan,

absolutely no worries. Thank you for your work so far it helped a lot!

@all: Anyone else who would quickly be able to run the script on Powerpoint (ideally '16) and provide me with a feedback and potential resolution? :slight_smile:

Best regards and thx,
Phil

Do make it easy for everyone please find below the current status of the script:

destinationFolderPOSIXPath would naturally need to be replaced…



on savePPT()
	-- Create a new document and save it into the Documents folder
	
	-- generate the default file name
	set todaysDate to (current date)
	set fullName to the text returned of (display dialog "Enter Full Name" with title "Master PPT Query" default answer "")
	set the nameToUse to 
		("Company Presentation - " & fullName & " - " & (month of todaysDate) as string) & 
		space & (year of todaysDate) as string
	--> "Monthly Report - December 2014"
	
	-- make sure the file name is not in use
	set destinationFolderPOSIXPath to "/Users/(....)/Automatic Export/" as string
	set destinationFolderHFSPath to (POSIX file destinationFolderPOSIXPath) as text
	repeat with i from 0 to 100000
		if i is 0 then
			set incrementText to ""
		else
			set incrementText to "-" & (i as string)
		end if
		set thisFileName to nameToUse & incrementText & ".pptx"
		set thisFilePath to destinationFolderHFSPath & thisFileName
		tell application "Finder"
			if not (exists document file thisFilePath) then exit repeat
		end tell
	end repeat
	
	set pdfPath to (destinationFolderHFSPath & nameToUse & incrementText & ".pdf")
	close access (open for access file thisFilePath with write permission)
	close access (open for access file pdfPath with write permission)
	
	tell application "Microsoft PowerPoint"
		activate
		-- create a new document and store its reference in a variable
		set thisDocument to active presentation
		-- save the document
		save thisDocument in file thisFilePath
		save thisDocument in file pdfPath as save as PDF
	end tell
end savePPT


I found this web page :
https://stackoverflow.com/questions/41886380/using-applescript-to-open-ms-powerpoint-2016-file

It confirms the fact that creating files as I did is required (they use an other scheme but the result is the same).
They use the same syntax than you to save in a PDF file.
So it seems that the syntax is not the problem.
I’m puzzled by three lines in your code :

 activate
       -- create a new document and store its reference in a variable
       set thisDocument to active presentation

Are you sure that they really create a document ?

When you will have a version doing the job, it will perhaps be safe to add code building an unique name for the PDF replicating the one used for the pptx.
At this time the code assumes that there is no pdf using the same name than the new pdf which may be a wrong assumption.

Yvan KOENIG running Sierra 10.12.5 in French (VALLAURIS, France) jeudi 13 juillet 2017 12:34:48

Hi Yvan,

thank you for your continuous support… :slight_smile:

It seems I just found the issue with the help of this resource:
http://www.mactech.com/articles/mactech/Vol.23/23.03/23.03AppleScriptPowerPoint/index.html

I now changed the syntax of the save command to the following:


	tell application "Microsoft PowerPoint"
		activate
		-- create a new document and store its reference in a variable
		set thisDocument to active presentation
		-- save the document
		save active presentation in thisFilePath as save as presentation
		save active presentation in pdfPath as save as PDF
	end tell

It creates an ppt instead of a pptx but this is sufficient for my needs.

Thank you a lot Yvan!!! :slight_smile: :slight_smile:

Issue seems to be resolved.

Best regards,
Phil

you even could remove the thisDocument def…


	tell application "Microsoft PowerPoint"
		activate
		-- save the document
		save active presentation in thisFilePath as save as presentation
		save active presentation in pdfPath as save as PDF
	end tell

Mhmm… ok there is another minor issue.

When saving the PDF I consequently getting asked to grant access to the location where it is saved (which I can) but is there a way of granting access without the dialogue to be clicked away manually?

Think I found the root cause…

http://www.rondebruin.nl/mac/mac034.htm

The problem is supposed to be solved by the instruction

   close access (open for access file pdfPath with write permission)

If you look in the AppleScript dictionary of Powerpoint I guess that you will see the way to force the app to save the doc as a pptx file.

Maybe you do that :

Go to : http://www.mugginsoft.com/content/ASDictionary
Download ASDictionary 0.13.2
Run it to export the PowerPoint dictionary in an html file.

Then send the html file to
k o e n i g . y v a n @ s f r . f r (without the space characters)
Maybe I would be able to find in it the required information.

Yvan KOENIG running Sierra 10.12.5 in French (VALLAURIS, France) jeudi 13 juillet 2017 16:19:57