Jump to content

PPT Quit not executing


Recommended Posts

I'm assuming this issue relates to the changes to COM objects in the beta build, but I'm trying to execute the following code:

$oPPT = ObjCreate("PowerPoint.Application")
                $oPresentation = $oPPT.Presentations.Open(@ScriptDir&"\test.pptx")
                If @error Then
                    MsgBox(0, "Error", "Error opening Presentation")
                    Exit
                EndIf
                $oPresentation.Save
                $oPresentation.Close
                $oPPT.Quit

and all of the commands other than the Quit command work. I tried it in the prod version (3.3.12) and it seems to have the same issue (doesn't close powerpoint). I've used this command before and it use to work so I'm not sure what I'm doing wrong or if there was a regression in autoit itself. Can anyone confirm if this function works for them or not?

Link to comment
Share on other sites

Have you tried the PPT UDF which can be found in the Examples Scripts forum?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

BTW: It is suggested to have brackets after a method. So it should be:

$oPPT = ObjCreate("PowerPoint.Application")
$oPresentation = $oPPT.Presentations.Open(@ScriptDir&"\test.pptx")
If @error Then
    MsgBox(0, "Error", "Error opening Presentation")
    Exit
EndIf
$oPresentation.Save()
$oPresentation.Close()
$oPPT.Quit()

 

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Jewtus,
I'm sure a COM error handler will help to solve this mystery! Please have a look at ObjEvent.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

works fine for me also:

$oPPT = ObjCreate("PowerPoint.Application")
$oPresentation = $oPPT.Presentations.Open(@ScriptDir & "\test.pptx")
If @error Then
    MsgBox(0, "Error", "Error opening Presentation")
    Exit
EndIf
$oPresentation.Save
$oPresentation.Close
$oPPT.Quit

...

ill get to that... i still need to learn and understand a lot of codes graduated.gif

Correct answer, learn to walk before you take on that marathon.

Link to comment
Share on other sites

@water I was using the UDF from the examples to grab just the parts I need (this tool I'm building is supposed to be very small and simple because other people need to understand how to mod it... and most of them struggle with some of the most basic stuff because they are not techies/Programmers)

 

I actually use a pop up logged that I modded from a logger I found in an example somewhere:

$oMyError = ObjEvent("AutoIt.Error","MyErrFunc")
Func MyErrFunc()
  $HexNumber=hex($oMyError.number,8)
  MsgBox(0,"","_______------- Error -------_______"       & @CRLF & _
             "err.description is: "    & @TAB & $oMyError.description    & @CRLF & _
             "err.windescription:"     & @TAB & $oMyError.windescription & @CRLF & _
             "err.number is: "         & @TAB & $HexNumber              & @CRLF & _
             "err.lastdllerror is: "   & @TAB & $oMyError.lastdllerror   & @CRLF & _
             "err.scriptline is: "     & @TAB & $oMyError.scriptline     & @CRLF & _
             "err.source is: "         & @TAB & $oMyError.source         & @CRLF & _
             "err.helpfile is: "       & @TAB & $oMyError.helpfile       & @CRLF & _
             "err.helpcontext is: "    & @TAB & $oMyError.helpcontext _
            )
  SetError(0)  ; to check for after this function returns
Endfunc

Not really sure how to look at just eh oPPT to handle the event and get details. Would I just tweak the $oMyerror to something like this

$oMyError2 = ObjEvent($oPPT,"MyErrFunc")

Still getting more familiar with COM objects so I'm not 100% sure on how to capture what is going on. I have several excel functions prior to this that I think are causing the issue, but I don't really know how to debug it.

 

This is the full code for what I'm executing prior to this function for some more context:

$oExcel = ObjCreate("Excel.Application")
            $oBookMaster=$oExcel.WorkBooks.Open (@ScriptDir&"\Auto.xlsx")
            $oSheetMaster=$oBookMaster.Worksheets("Main")
            $oExcel.DisplayAlerts = False
            $oExcel.Visible = True
            $tContinue=MsgBox(4,"Continue?","Please validate and select YES to continue")
            If $tContinue=6 Then
                ;Set Backup Path and archive files
                $sTime=@YEAR&"-"&@MON&"-"&@MDAY&" "&@HOUR&"-"&@MIN&"-"&@SEC
                $FolderPath = @ScriptDir&"\Archive\"&$sTime
                $aFullPaths=_FileListToArrayRec(@ScriptDir&"\Current","*.xl*",1,1) ;Get All Files full path (recursive lookup)
                ArchiveFiles($aFullPaths,$FolderPath)
                ;Backup Master excel
                FileCopy(@ScriptDir&"\Auto.xlsx",@ScriptDir&"\Archive\"&$sTime&"\auto.xlsx",1)
                ;Update PPT
                $oPPT = ObjCreate("PowerPoint.Application")
                $oPresentation = $oPPT.Presentations.Open(@ScriptDir&"\PPT Auto.pptx")
                If @error Then
                    MsgBox(0, "Error", "Error opening Presentation")
                    Exit
                EndIf
                $oPresentation.Save
                $oPresentation.Close
                $oPPT.Quit

 

Link to comment
Share on other sites

Easiest way to get COM errors is to add the following lines at hte top of your script:

#include <Debug.au3>
_DebugSetup()
_DebugCOMError()

You can modify _DebugSetup to direct the output to a file.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Weird... I added this to my script:

_DebugSetup(Default, True, 1, Default, True)
_DebugCOMError(1)

and it pops up the gui and grabs my system specs then It continues to run but doesn't catch anything when the PPT function is called. I even tried forcing a failure to capture what was going on and it didn't catch anything. I turned my pop up logged off and then it was catching the deliberate failure ($oPPT.DIE) but its not really even giving me anything that I know what to do with:

2015/06/16 09:57:52 COM Error encountered in Full.au3 () :
    Number            = 0x00000000 ()
    WinDescription    =
    Description       =
    Source            =
    HelpFile          =
    HelpContext       =
    LastDllError      =
    Retcode           = 0x00000000

I'm going to try this again with the UDF and see if it works for me (open and save is pretty simple so it should be quick to tweak my code).

Link to comment
Share on other sites

Ok, back to your first post ;)
You wrote: "all of the commands other than the Quit command work".
How do you notice that Quit doesn't work?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

I have the same issue with the UDF:

$objPPT=_PPT_PowerPointApp()
                $objPres=_PPT_PresentationOpen($objPPT,@ScriptDir&"\Test.pptx")
                _PPT_PresentationSaveAs($objPres, @ScriptDir&"\Archive\"&$sTime&"\Test.pptx")
                _PPT_PresentationClose($objPres) ; Close presentation
                _PPT_PowerPointQuit($objPPT) ;Exit PowerPoint

It does everything but close the PPT application itself....

Link to comment
Share on other sites

Ok, back to your first post ;)
You wrote: "all of the commands other than the Quit command work".
How do you notice that Quit doesn't work?

​Power point is still open when the script is complete. It saves and closes the presentation, but the application is still open.

Link to comment
Share on other sites

I tried isolating the part that opens and closes to see if its something else going on (using the UDF function) and when I try this:

$objPPT=_PPT_PowerPointApp()
$objPres=_PPT_PresentationOpen($objPPT,@ScriptDir&"\TEST.pptx")
_PPT_PresentationSaveAs($objPres, @ScriptDir&"\00-Archive\"&$sTime&"\TEST.pptx")
_PPT_PresentationClose($objPres) ; Close presentation
_PPT_PowerPointQuit($objPPT) ;Exit PowerPoint

It errors

"C:\Sources\NewTool (autoit based)\Examples\Powerpoint.au3" (367) : ==> The requested action with this object has failed.:
$obj.SaveAs($filename)
$obj^ ERROR

but when I use

$sTime=@YEAR&"-"&@MON&"-"&@MDAY&" "&@HOUR&"-"&@MIN&"-"&@SEC
$objPPT=_PPT_PowerPointApp()
$objPres=_PPT_PresentationOpen($objPPT,@ScriptDir&"\TEST.pptx")
_PPT_PresentationSaveAs($objPres, @ScriptDir&"\00-Archive\TEST.pptx")
_PPT_PresentationClose($objPres) ; Close presentation
_PPT_PowerPointQuit($objPPT) ;Exit PowerPoint

It operates without any issue. Why would adding a date string to a folder name cause this?

Link to comment
Share on other sites

Maybe the maximum path length is exceeded.
Can you manually save the file with the same name into this directory?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

I'm thinking that I'll just save it to the @scriptdir with a different file name then move it to the final location and rename it (the final location name should be the same as the source file). I was thinking string length issue when I noticed that myself. Think this should take care of the issue though. I'll post updated code when I finish it up.

Edited by Jewtus
Link to comment
Share on other sites

Well... It seems like there must be an open object or an object with the same name or something, because when I put the same code I isolated Powerpoint doesn't close. I reverted to my original code with the stringlength in mind and same issue. I functionalized it and it works without issue now.

 

Func ArchivePPT($sTime)
    $oPPT = ObjCreate("PowerPoint.Application")
    $oPresentation = $oPPT.Presentations.Open(@ScriptDir&"\test.pptx")
    If @error Then
        MsgBox(0, "Error", "Error opening Presentation")
        Exit
    EndIf
    $oPresentation.SaveAs(@ScriptDir&"\Stage.pptx")
    $oPresentation.Close
    $oPPT.Quit
    ;Backup PPT
    FileMove(@ScriptDir&"\Stage.pptx",@ScriptDir&"\00-Archive\"&$sTime&"\Test.pptx",1)
EndFunc

 

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...