Jump to content

Detecting Powerpoint slide from multiple open slides


rg20
 Share

Recommended Posts

Hello All,

 

I am running into an issue hopefully the AutoIT gods are able to help

 

I am running an app that automatically opens a PowerPoint slide.  I am using the Powerpoint.au3 scripts and trying to attach to the slide I need.

I modified the attach function to read as 

 

Func _PPT_PresentationAttach($sString, $sMode = Default)
    Local $oPresentation, $iCount = 0, $sCLSID_Presentation = "{91493444-5A91-11CF-8700-00AA0060263B}" ; Microsoft.Office.Interop.PowerPoint.PresentationClass
    If $sMode = Default Then $sMode = "FilePath"
    While True
        $oPresentation = ObjGet("", $sCLSID_Presentation, $iCount + 1)
        ConsoleWrite($oPresentation.Application.Caption & @LF)
        If @error Then Return SetError(1, @error, 0)
        Switch $sMode
            Case "filename"
                If $oPresentation.Name = $sString Then Return $oPresentation
            Case "filepath"
                If $oPresentation.FullName = $sString Then Return $oPresentation
            Case "title"
                If $oPresentation.Application.Caption = $sString Then Return $oPresentation
            Case "partialTitle"
                MsgBox(1,"","Partial Title - " & $sString & " Against - " & $oPresentation.Application.Caption)
                If StringInStr($oPresentation.Application.Caption, $sString) Then Return $oPresentation
            Case Else
                Return SetError(2, 0, 0)
        EndSwitch
        $iCount += 1
    WEnd
EndFunc   ;==>_PPT_PresentationAttach

 

I am calling that script as

$title = WinGetTitle("[ACTIVE]")
_DebugOut("WINDOW - current window is "& $title)
while not (StringInStr ($title , "Presentation"))
    send ("!{TAB}")
    $title = WinGetTitle("[ACTIVE]")
    _DebugOut("WINDOW - current window is (need powerpoint)" & $title)
    sleep(500)
wend

    $objPPTCreated = _PPT_PresentationAttach("Presentation","partialTitle")
    ConsoleWrite("Borg = " & _PPT_SlideCount($objPPSBorg) & " New = " & _PPT_SlideCount($objPPTCreated) &" with caption = " & $objPPTCreated.Application.Caption & @LF)

So one file that is open will have a name that is known call it "Borg" for now

The other is new, so it will have the word "Presentation" in the title.

 

When I come out of the script I get this in the console

Borg = 3 New = 3 with caption = Presentation7 - Microsoft PowerPoint

So Borg should have 3 slides, New should have 1, not 3, but the caption is correct.

 

These are 2 instances of Powerpoint, not one powerpoint with 2 books.

I then proceed to save with 

$newPPT = _PPT_PresentationSaveAs($objPPTCreated,$SaveFile)

but the Borg book gets saved with the new name, not the new presentation.

 

Thoughts?

Link to comment
Share on other sites

  • Moderators

Moved to General Help and Support as Developer Forum clearly states "Do not post AutoIt topics here"

Edited by JLogan3o13

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

Will have a look at it tomorrow :)

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

For further reference, I added the following

 

Func _PPT_PresentationSaveAs(ByRef $obj, $filename)
    If IsObj($obj) <> 1 Then
        SetError(1)
        Return 0
    Else
        ConsoleWrite("Saving Object as before " & $obj.Application.Caption & @LF)
        $obj.SaveAs($filename)
        ConsoleWrite("Saving Object as After " & $obj.Application.Caption & @LF)
    Endif
EndFunc

and got the following output

Saving Object as before Presentation1 - Microsoft PowerPoint
Saving Object as After Presentation1 - Microsoft PowerPoint

Link to comment
Share on other sites

I have added function _PPT_PresentationList to the UDF:

; #FUNCTION# ====================================================================================================================
; Name...........: _PPT_PresentationList
; Description ...: Returns a list of currently open presentations
; Syntax.........: _PPT_PresentationList($oPPT)
; Parameters ....: $oPPT - PowerPoint application object to retrieve the list of presentations from
; Return values .: Success - a two-dimensional zero based array with the following information:
;                  |0 - Object of the workbook
;                  |1 - Name of the workbook/file
;                  |2 - Complete path to the workbook/filethe PowerPoint presentation object
;                  Failure - 0 and sets @error.
;                  |1 - $oPPT is not an object or not an application object
; Author ........: water
; Modified.......:
; Remarks .......:
; Related .......: None
; Link ..........:
; Example .......: Yes
; ===============================================================================================================================
Func _PPT_PresentationList($oPPT)
    Local $aPresentations[1][3], $iIndex = 0
    If IsObj($oPPT) = 0 Or ObjName($oPPT, 1) <> "_Application" Then Return SetError(1, 0, 0)
    Local $iTemp = $oPPT.Presentations.Count
    ReDim $aPresentations[$iTemp][3]
    For $iIndex = 0 To $iTemp - 1
        $aPresentations[$iIndex][0] = $oPPT.Presentations($iIndex + 1)
        $aPresentations[$iIndex][1] = $oPPT.Presentations($iIndex + 1).Name
        $aPresentations[$iIndex][2] = $oPPT.Presentations($iIndex + 1).Path
    Next
    Return $aPresentations
EndFunc   ;==>_PPT_PresentationList

So you can loop through the array and select the desired presentation. The presentation object can be retrieved from element 0 of the respective row.

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

NB: I have modified _PPT_PresentationAttach so it now supports partial match by setting a new flag:

; #FUNCTION# ====================================================================================================================
; Name...........: _PPT_PresentationAttach
; Description ...: Attaches to the presentation where the search string matches based on the selected mode.
; Syntax.........: _PPT_PresentationAttach($sString[, $sMode = "FilePath"[, $bPartialMatch = False]])
; Parameters ....: $sString       - String to search for.
;                  $sMode         - [optional] specifies search mode:
;                  |FileName      - Name of the open presentation
;                  |FilePath      - Full path to the open presentation (default)
;                  |Title         - Title of the PowerPoint window
;                  $bPartialMatch - [optional] When $sMode = Title then $sString must fully match when False (default) or partial if True
; Return values .: Success - the PowerPoint presentation object.
;                  Failure - 0 and sets @error.
;                  |1 - An error occurred. @extended is set to the COM error code
;                  |2 - $sMode is invalid
;                  |3 - $sString can't be found in any of the open presentations
; Author ........: water
; Modified.......:
; Remarks .......:
; Related .......: _PPT_PresentationClose, _PPT_PresentationNew, _PPT_PresentationOpen
; Link ..........:
; Example .......: Yes
; ===============================================================================================================================
Func _PPT_PresentationAttach($sString, $sMode = Default, $bPartialMatch = Default)
    Local $oPresentation, $iCount = 0, $sCLSID_Presentation = "{91493444-5A91-11CF-8700-00AA0060263B}" ; Microsoft.Office.Interop.PowerPoint.PresentationClass
    If $sMode = Default Then $sMode = "FilePath"
    If $bPartialMatch = Default Then $bPartialMatch = False
    While True
        $oPresentation = ObjGet("", $sCLSID_Presentation, $iCount + 1)
        If @error Then Return SetError(1, @error, 0)
        Switch $sMode
            Case "filename"
                If $oPresentation.Name = $sString Then Return $oPresentation
            Case "filepath"
                If $oPresentation.FullName = $sString Then Return $oPresentation
            Case "title"
                If $bPartialMatch Then
                    If StringInStr($oPresentation.Application.Caption, $sString) > 0 Then Return $oPresentation
                Else
                    If $oPresentation.Application.Caption = $sString Then Return $oPresentation
                EndIf
            Case Else
                Return SetError(2, 0, 0)
        EndSwitch
        $iCount += 1
    WEnd
    Return SetError(3, 0, 0)
EndFunc   ;==>_PPT_PresentationAttach

 

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

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