Thursday, July 27, 2017

#1 2017-07-11 07:41:28 am

phil_zrh
Member
Registered: 2017-06-29
Posts: 14

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

Applescript:


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

Offline

 

#2 2017-07-11 08:09:10 am

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 3127

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

phil_zrh wrote:

Applescript:


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 :

Applescript:

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

by

Applescript:

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

Offline

 

#3 2017-07-11 08:45:41 am

phil_zrh
Member
Registered: 2017-06-29
Posts: 14

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

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?

Offline

 

#4 2017-07-11 09:16:21 am

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 3127

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

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

phil_zrh wrote:

Applescript:


   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


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

Applescript:

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

or maybe

Applescript:

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

If it's not sufficient try:

Applescript:


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 hmm

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

Offline

 

#5 2017-07-11 09:44:59 am

phil_zrh
Member
Registered: 2017-06-29
Posts: 14

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

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...

Applescript:


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

Offline

 

#6 2017-07-11 10:56:42 am

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 3127

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

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

Applescript:


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

Offline

 

#7 2017-07-11 03:49:48 pm

phil_zrh
Member
Registered: 2017-06-29
Posts: 14

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

Hi Yvan (my sincere apologies! wink),

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

Offline

 

#8 2017-07-12 05:10:46 am

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 3127

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

What you get are the files created by the instructions :

Applescript:

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

Offline

 

#9 2017-07-12 06:20:08 am

phil_zrh
Member
Registered: 2017-06-29
Posts: 14

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

Great, thx for your efforts! This highly appreciated.

So Merdosoft finally makes access to your home at least for a few hours... big_smile

Offline

 

#10 2017-07-12 08:11:55 am

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 3127

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

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

Offline

 

#11 2017-07-12 03:47:00 pm

phil_zrh
Member
Registered: 2017-06-29
Posts: 14

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

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? smile

Best regards and thx,
Phil

Offline

 

#12 2017-07-12 03:50:51 pm

phil_zrh
Member
Registered: 2017-06-29
Posts: 14

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

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

destinationFolderPOSIXPath would naturally need to be replaced...

Applescript:



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

Last edited by phil_zrh (2017-07-12 03:51:55 pm)

Offline

 

#13 2017-07-13 05:35:06 am

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 3127

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

I found this web page :
https://stackoverflow.com/questions/418 … -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 :

Applescript:

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

Last edited by Yvan Koenig (2017-07-13 05:41:08 am)

Offline

 

#14 2017-07-13 06:37:32 am

phil_zrh
Member
Registered: 2017-06-29
Posts: 14

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

Hi Yvan,

thank you for your continuous support... smile

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

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

Applescript:


   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!!!! smile smile

Issue seems to be resolved.

Best regards,
Phil

Offline

 

#15 2017-07-13 06:38:54 am

phil_zrh
Member
Registered: 2017-06-29
Posts: 14

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

you even could remove the thisDocument def...

Applescript:


   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

Offline

 

#16 2017-07-13 06:45:48 am

phil_zrh
Member
Registered: 2017-06-29
Posts: 14

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

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?

Offline

 

#17 2017-07-13 06:49:40 am

phil_zrh
Member
Registered: 2017-06-29
Posts: 14

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

Think I found the root cause...

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

Offline

 

#18 2017-07-13 09:20:04 am

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 3127

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

The problem is supposed to be solved by the instruction

Applescript:

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

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)