Jump to content
Sign in to follow this  
Ramses

Powerpoint ExportAsFixedFormat

Recommended Posts

Ramses

Hi,

this should be easy and it should be working.

I have to check a number of Powerpoint Files and assign a password (if they don't have one yet) and export the file to a pdf (if it doesn't exist yet.)

$FilePath and $FileName are defined elsewhere; you just need to point them at something like

$FilePath = "c:presentation.ppt"

$FileName = "presentation.ppt"

The script opens the file, waits for it to either open or request a password (covers for German and English installations - I know it's not pretty.)

If a password is requested, it is supplied here.

I am then trying to export the file to pdf, and this keeps failing.

I have no idea what else I should be expected to do here. any pointer or suggestions?

This is for autoit v3.3.8.1, Microsoft Office 2010 and Windows 7 (Enterprise)

ShellExecute($FilePath)

                    Do

                    until WinExists("Kennwort")


                    ; we have opened the file. At this stage, there should be a full window, or a password prompt. If the latter, we'll supple the password and wait

                    if WinExists("Kennwort") then
                        WinActivate ("Kennwort")
                        ControlSetText ("Kennwort", "", 6, "Password")
                        ControlClick ("Kennwort", "", 1)
                    EndIf

                    if WinExists("Kennwort") then
                        WinActivate ("Kennwort")
                        ControlSetText ("Kennwort", "", 6, "Password")
                        ControlClick ("Kennwort", "", 1)
                    EndIf

                    Do

                    until WinExists($FileName)


                    sleep (10000)

                    WinActivate ($FileName)


                    $word = Objget("", "PowerPoint.Application")

                    $word.activepresentation.ExportAsFixedFormat ($FilePath & ".pdf", 2)
                    $word.activepresentation.close



                    $word.Quit

Share this post


Link to post
Share on other sites
water

 

I am then trying to export the file to pdf, and this keeps failing.

This doesn't tell us very much.

Can you please be more specific and describe the error message or whaterver tells you that your script "fails"?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
Ramses

Sure.

By now I was just expecting my error to be glaringly obvious to the initiated....

See ...\test.au3 (41) : ==> The requested action with this object has failed.:
$word.ExportAsFixedFormat ("c:\present.pdf", 2)
$word.ExportAsFixedFormat ("c:\present.pdf", 2)^ ERROR
->18:06:54 AutoIt3.exe ended.rc:1

Now, I *know* I am getting the Object assigned to $word - I can close the presentation and the application with

$word.activepresentation.close
$word.Quit

I have tried to use the export function on the application rather than the presentation - but that didn't help. Also, the parameter 2 I am passing here should indicate PDF format. "pdf" and "ppFixedFormatTypePDF" didn't seem to help, either.

Share this post


Link to post
Share on other sites
water

Shouldn't it be:

$word.ActivePresentation.ExportAsFixedFormat ("c:\present.pdf", 2)

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
Ramses

 

Shouldn't it be:

$word.ActivePresentation.ExportAsFixedFormat ("c:\present.pdf", 2)

I tried that, too. Same result.

I don't know what it *should* be - I have tried everything I think it *should* be and a good few things that I don't think it should be, too.

So, the reference for 2007 (http://msdn.microsoft.com/en-us/library/bb231096%28v=office.12%29.aspx ) and the one for  2013 (http://msdn.microsoft.com/de-de/library/office/ff746080.aspx) both seem to agree that this command exists. I can't even find the docs for 2010.

Share this post


Link to post
Share on other sites
water

The docs for PP 2010 can be found here.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
Ramses

The docs for PP 2010 can be found here.

Oh cool. I was trying to dig through the MS navigation and hit a dead end. Doesn't change anythng, though. The docs haven't changed, and it's still not working. I can't even get the supplued VBA example to work.

http://msdn.microsoft.com/en-us/library/ff746080%28v=office.14%29.aspx

VBA throws a runtime error that leads me here:

http://support.microsoft.com/kb/285472/en-us

Can't figure that out, either ...

Share this post


Link to post
Share on other sites
water

Do you have installed the full Office suite (not just the trial version or upgraded from a trial version)?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
Ramses

I am sorry for not getting back to you earlier ...

Yes, I have the full office suite installed.

Some more information:

Sub exportme()
ActivePresentation.ExportAsFixedFormat ActivePresentation.Path & "\" & ActivePresentation.Name & ".pdf", ppFixedFormatTypePDF
End Sub

The above is a VBA macro that runs fine from within Powerpoint. PpFixedFormatTypePDF is of type PpFixedFormatType

AutoIT is throwing a type mismatch error when I make the call - it seems something somewhere is not happy with my passing of ppFixedFormatTypePDF - which I have done as "ppFixedFormatTypePDF", 2, "2", as a constant and variable as well.

Anyway, I mostly just wanted to thank you for your efforts, albeit I am very late doing so. I think I can work around the actual problem by calling a macro...

Share this post


Link to post
Share on other sites
water

Next thing to do is to add a COM error handler to get better diagnostic information:

; Error monitoring. This will trap all COM errors while alive.
Global $oErrorHandler = ObjEvent("AutoIt.Error", "_ErrFunc")

; Your code goes here <===================

; User's COM error function. Will be called if COM error occurs
Func _ErrFunc($oError)

    ConsoleWrite("err.number is: " & @TAB & $oError.number & @CRLF & _
            "err.windescription:" & @TAB & $oError.windescription & @CRLF & _
            "err.description is: " & @TAB & $oError.description & @CRLF & _
            "err.source is: " & @TAB & $oError.source & @CRLF & _
            "err.helpfile is: " & @TAB & $oError.helpfile & @CRLF & _
            "err.helpcontext is: " & @TAB & $oError.helpcontext & @CRLF & _
            "err.lastdllerror is: " & @TAB & $oError.lastdllerror & @CRLF & _
            "err.scriptline is: " & @TAB & $oError.scriptline & @CRLF & _
            "err.retcode is: " & @TAB & $oError.retcode & @CRLF & @CRLF)
EndFunc   ;==>_ErrFunc

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
Ramses

That's what I did. Further searches didn't provide any better results.

err.number is:     80020005
err.windescription:    Typkonflikt. (type mismatch)

err.description is:     
err.source is:     
err.helpfile is:     
err.helpcontext is:     18055848
err.lastdllerror is:     0
err.scriptline is:     24
err.retcode is:     0

Share this post


Link to post
Share on other sites
water

Google doesn't help much.

The only possible solution I could found is to specify ALL (even the optional parameters): http://stackoverflow.com/questions/893675/powerpoint-2007-sp2-exportasfixedformat-in-powershell:
"PowerPoint's ExportAsFixedFormat will return "Type Mismatch" when the "optional" parameters are missing. Only if all of the parameters are provided is the puArgErr value returned by Invoke meaningful."


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×