Jump to content

How to access the already opened ppt - (Moved)


Recommended Posts

Hi All

I have requirement to open a PPT and Excel from share point site, then edit and save.

Currently Clicking the PPT and Excel doing from selenium, Here i need to access the opened ppt/Excel and add few text and save. After that check in and close.

Then again i need to validate that same text presence on the ppt and excel. Can you anyone help me on this.

Note: The same flow i have achieved in word which is working like a charm with help of forum. Currently the same flow validation WORD-Done,PPT,EXCEL-Pending

Link to comment
Share on other sites

Welcome to AutoIt and the forum!

Did you search the forum for "SharePoint and Excel"? IIRC this has been discussed a few times.

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

Thanks for your immediate reply and greetings. I did search sometime in google and not found anything specific to my test case flow in PPT. I could see only few things which is related to new ppt/excel opening ,edit/save and locally download the document from sharepoint and edit. I just downloaded the PPT Utils from your forum reply. Even i don't know where i can place. Currently placing under script directory. please guide me if you are free. Here For me, I don't have any concern in accessing the ppt and Excel in share point. my search only about How to take a reference of opened PPT and excel .  But I will do search in our forum meanwhile.

Link to comment
Share on other sites

There is an UDF available for PowerPoint (for download please have a look at my signature). Function _PPT_PresentationAttach does what you are looking for.

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

Thanks for your reply @water, I just tried your _PPT_PresentationAttach, However it doesn't take file name, title name, but Only working with file path. Find my below code.

Local $sPresentation = "Presentation1 - PowerPoint" ; window title

$oPresentation = _PPT_PresentationAttach($sPresentation)
If @error Then Exit MsgBox($MB_SYSTEMMODAL, "PowerPoint UDF: _PPT_PresentationAttach Example 1", "Error attaching to '" & $sPresentation & "'." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
MsgBox($MB_SYSTEMMODAL, "PowerPoint UDF: _PPT_PresentationAttach Example 1", "Search by 'filepath':" & @CRLF & @CRLF & "Successfully attached to presentation '" & $sPresentation & "'.")

Returning @error=2 and @ext=0

Could you pls help me out with sample code.

Link to comment
Share on other sites

According to the documentation in the UDF header it takes

;                  $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

So you should use

Local $sPresentation = "Presentation1 - PowerPoint" ; window title
$oPresentation = _PPT_PresentationAttach($sPresentation, "Title")

 

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

Thanks for guiding me @water. Still facing the issue , but now i am getting @err=1 @ext=-2147352570,
 

Steps followed,

> Opened PPT document  with title name "Presentation1 - PowerPoint "

> ran the script

find below my complete code.

#include <PowerPoint.au3>
#include <MsgBoxConstants.au3>

Local $sPresentation = "Presentation1 - PowerPoint"
$oPresentation = _PPT_PresentationAttach($sPresentation, "title")
If @error Then Exit MsgBox($MB_SYSTEMMODAL, "PowerPoint UDF: _PPT_PresentationAttach Example 1", "Error attaching to '" & $sPresentation & "'." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
MsgBox($MB_SYSTEMMODAL, "PowerPoint UDF: _PPT_PresentationAttach Example 1", "Search by 'filepath':" & @CRLF & @CRLF & "Successfully attached to presentation '" & $sPresentation & "'.")
Link to comment
Share on other sites

@water, Just debugged some time in the code and verified with partial text, its working good and ppt attached successfully. I don't know why its not working the exact match. Let me check the edit, save and search functionality and update in the same thread. Thanks again for your guidance.  :)

Link to comment
Share on other sites

After successfully attached, Add text code not responding. Could you please check, what i did wrong.


#include "PowerPoint.au3"
#include <misc.au3>

$oMyError = ObjEvent("AutoIt.Error","MyErrFunc")
sleep(3000)

Local $sPresentation = @ScriptDir & "\Presentation1.pptx"
$oPresentationtest = _PPT_PresentationAttach($sPresentation,"Title",True)
If @error Then Exit MsgBox($MB_SYSTEMMODAL, "PowerPoint UDF: _PPT_PresentationAttach Example 1", "Error attaching to '" & $sPresentation & "'." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
MsgBox($MB_SYSTEMMODAL, "PowerPoint UDF: _PPT_PresentationAttach Example 1", "Search by 'filepath':" & @CRLF & @CRLF & "Successfully attached to presentation '" & $sPresentation & "'.")
_PPT_SlideAddTextBox($oPresentationtest,100, 100, 400, 100) ;add a plain textbox
_PPT_SlideTextFrameSetText($oPresentationtest, 1, "A simple textbox") ;add text to textbox
_PPT_SlideTextFrameSetFontSize($oPresentationtest, 1, 48)

Link to comment
Share on other sites

My PowerPoint UDF is based on another UDF written by Toady.
I wanted to extend this UDF and make it more UDF-like (e.g. examples, help file ...).
But as you can see, it is still in beta.
When you copy functions from the root UDF I'm quite sure the do not work with my implementation.
So we would need to move this functions to my UDF and alter them accordingly.

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

Thanks @water, Based on your input i just dug more on this, found the solution. Just small mistake because of document info misunderstanding.

Opened window should be ACTIVE- Known 

Need to know the exact info about the parameter, like,

filename : Presentation1.pptx
Title: Presentation1
filepath: D:\AutoIT\ppt\Presentation1.pptx

I just confused with title is like window title(AutoIT Element finder title) and Filename is like without Extension(.pptx)

Now code able to identify Active window and insert my text and save.

@water
a. Search task is pending, if you have any idea about how to search and validate with  some string, please help on that. My Complete code is for forum members

b. where i can place the your PPT UDF in AUTOIT folder, Currently that is in script directory. I Need to put  all lib function in default location.
 

Access the already opened PPT: 

#include <PowerPoint.au3>
#include <MsgBoxConstants.au3>
sleep(5000)

; *****************************************************************************
; Attach to the first presentation where the file path matches
; *****************************************************************************

Local $sPresentation = "Presentation1.pptx"
Local $oPresentation = _PPT_PresentationAttach($sPresentation,"filename")
$objSlide1 = _PPT_SlideCreate($oPresentation, 1, $PPLAYOUTTEXT) ;Create a new slide with text layout, index = 1
_PPT_SlideTextFrameSetText($objSlide1, 1, "Slide #1 Test")
_PPT_SlideTextFrameSetText($objSlide1, 2, "Each slide will display for 5 seconds")
_PPT_SlideTextFrameSetFont($objSlide1 , 2, "Comic Sans MS") ;set font for textframe number 2

_PPT_PresentationSave($oPresentation)

 

Link to comment
Share on other sites

1 minute ago, iburahim786 said:

Thanks @water, Based on your input i just dug more on this, found the solution. Just small mistake because of document info misunderstanding.

Opened window should be ACTIVE- Known 

Need to know the exact info about the parameter, like,

filename : Presentation1.pptx
Title: Presentation1
filepath: D:\AutoIT\ppt\Presentation1.pptx

I just confused with title is like window title(AutoIT Element finder title) and Filename is like without Extension(.pptx)

Now code able to identify Active window and insert my text and save.

@water
a. Search task is pending, if you have any idea about how to search and validate with  some string, please help on that. My Complete code is for forum members

b. where i can place your PPT UDF in AUTOIT folder, Currently that is in script directory. I Need to put  all lib function in default location.
 

Access the already opened PPT: 

#include <PowerPoint.au3>
#include <MsgBoxConstants.au3>
sleep(5000)

; *****************************************************************************
; Attach to the first presentation where the file path matches
; *****************************************************************************

Local $sPresentation = "Presentation1.pptx"
Local $oPresentation = _PPT_PresentationAttach($sPresentation,"filename")
$objSlide1 = _PPT_SlideCreate($oPresentation, 1, $PPLAYOUTTEXT) ;Create a new slide with text layout, index = 1
_PPT_SlideTextFrameSetText($objSlide1, 1, "Slide #1 Test")
_PPT_SlideTextFrameSetText($objSlide1, 2, "Each slide will display for 5 seconds")
_PPT_SlideTextFrameSetFont($objSlide1 , 2, "Comic Sans MS") ;set font for textframe number 2

_PPT_PresentationSave($oPresentation)

 

 

Link to comment
Share on other sites

I have modified function _PPT_PresentationList so you get exactly the parameters for _PPT_PresentationAttach (the zero-based array returns filename in column 1, filepath in column2 and title in column 3).
Title now gets derived from the caption of the first window in the presentation. The application.window.caption I used before was wrong :(

I suggest you first run _PPT_PresentationList to verify my code. It should return: filename : Presentation1.pptx, title: Presentation1 and filepath: D:\AutoIT\ppt\Presentation1.pptx.

Please find below the new versions of _PPT_PresentationAttach and _PPT_PresentationList (which you need to replace in the PPT.au3 UDF):

; #FUNCTION# ====================================================================================================================
; Name...........: _PPT_PresentationAttach
; Description ...: Attaches to the frist 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 (e.g. "Presentation1.pptx")
;                  |FilePath      - Full path to the open presentation (default) (e.g. "C:\Temp\Presentation1.pptx")
;                  |Title         - Caption of the first window of the presentation (e.g. "Presentation1.pptx [Write protected]")
;                  $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
                    If StringInStr($oPresentation.Windows(1).Caption, $sString) > 0 Then Return $oPresentation
                Else
                    ; If $oPresentation.Application.Caption = $sString Then Return $oPresentation
                    If $oPresentation.Windows(1).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
; #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 presentation
;                  |1 - Name of the presentation/file
;                  |2 - Complete path to the presentation/file
;                  |3 - Title of the presentation derived from the first window.caption of the presentation
;                  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][4], $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][4]
    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 & "\" & $aPresentations[$iIndex][1]
        $aPresentations[$iIndex][3] = $oPPT.Presentations($iIndex + 1).Windows(1).Caption
    Next
    Return $aPresentations
EndFunc   ;==>_PPT_PresentationList

 

Edited by water

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

On 7/27/2019 at 12:54 AM, iburahim786 said:

Opened window should be ACTIVE- Known 

There shouln't be the need to have a window active as the UDF uses COM to interact with PPT.

Quote

a. Search task is pending, if you have any idea about how to search and validate with  some string, please help on that. My Complete code is for forum members

b. where i can place the your PPT UDF in AUTOIT folder, Currently that is in script directory. I Need to put  all lib function in default location.

a. What do you want to search for? Text all over the presentation, Text in special elements of the presentation (textbox, footer/header ...)?
    I'm still unsure which functionality to put in a function of the PPT UDF.

b. In SciTE press Ctrl+1 for SciTEConfig. There you can set the User Include Folder.

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

10 hours ago, water said:

a. What do you want to search for? Text all over the presentation, Text in special elements of the presentation (textbox, footer/header ...)?
    I'm still unsure which functionality to put in a function of the PPT UDF.

For me, anything is fine. Just want to search a text in Slide, any place (textbox, footer/header ...etc) looks to be fine. I am putting the unique text every time. I think, You're going to write a single function can do all this. Because you're genius :)  to write all this in one function like you did in  _PPT_PresentationAttach (filename,path,title.)

 

10 hours ago, water said:

b. In SciTE press Ctrl+1 for SciTEConfig. There you can set the User Include Folder.

Thank you, After compiling to .exe, no need to worry about UDF/dependencies location and anywhere we can run .exe ?... Because I've been pondering  since day 1 do i really have to make sure all dependencies in same .exe location like powerpoint.au3, some defined UDF ? 

Link to comment
Share on other sites

The only thing you need is the exe. During "compilation" everything needed to run the script is packed into the exe.

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

1 hour ago, water said:

The only thing you need is the exe. During "compilation" everything needed to run the script is packed into the exe.

Thanks again, Hopefully waiting for my 1st Question ans i.e search a text/string in  entire PPT/ particular slide. :) 

Link to comment
Share on other sites

I have already started to search the web for a VBA solution. I hope to translate it to AutoIt quite soon. But please don't hold your breath :)

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