Jump to content

Rewrite of the PowerPoint UDF


water
 Share

Recommended Posts

9 hours ago, water said:

Use

; Example: Paste the clipboard content to the TextFrame in Slide 2, Shape 3 of the Presentation
$oObject = $oPresentation.Slides(2).Shapes(3).TextFrame.TextRange
$oObject.Paste()

 

How do I use this piece of code with _PPT_TextFindReplace?

Link to comment
Share on other sites

6 minutes ago, Floppy said:

How do I use this piece of code with _PPT_TextFindReplace?

You can't. As I described in a previous post this function only works with strings.
To handle this problem we need at least an example PPT presentation to test :) 

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.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 (NEW 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

  • 3 weeks later...
  • 3 weeks later...

Sorry for my late reply. I have been very busy and needed a vacation too.
Will work on this issue now and reply as soon as possible.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.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 (NEW 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 had a look and noticed that there is yet no find function that just returns the shape where the text has been found.
The Word UDF comes with a similar function.
Starting with tomorrow I no longer have a Windows / Office PC available to play with.
This means: I can still write code for PowerPoint but I can't test it :( 

If you take the task of testing the code I will do my very best and provide code to solve your problem.
 

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.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 (NEW 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

36 minutes ago, water said:

I had a look and noticed that there is yet no find function that just returns the shape where the text has been found.
The Word UDF comes with a similar function.
Starting with tomorrow I no longer have a Windows / Office PC available to play with.
This means: I can still write code for PowerPoint but I can't test it :( 

If you take the task of testing the code I will do my very best and provide code to solve your problem.
 

Sure! I can test it

Link to comment
Share on other sites

  • 2 weeks later...

First try for the find function. Returns an array with the objects of the Slide, Shape and TextRange where the text has been found.

; #FUNCTION# ====================================================================================================================
; Name...........: _PPT_TextFind
; Description ...: Find text on a single or selected slides.
; Syntax.........: _PPT_TextFind($oPresentation, $sFindText[, $vSlides = 0[, $vShapes = 0[, $iOccurrence = 0[, $bMatchCase = False[, $bWholeWords = False]]]]])
; Parameters ....: $oPresentation - Object of the presentation to process.
;                  $sFindText     - The text to be searched for.
;                  $vSlides       - [optional] Slides to process. See Remarks (default = 0 = all Slides).
;                  $vShapes       - [optional] Shapes to process on each selected Slide. See Remarks (default = 0 = all Shapes).
;                  $iOccurrence   - [optional] Number of times to search for $sFindText in a TextFrame (default = 0 = all occurrences).
;                  $bMatchCase    - [optional] Determines whether a distinction is made on the basis of case (default = False).
;                  $bWholeWords   - [optional] Determines whether only whole words are found (default = False).
; Return values .: Success - a two-dimensional zero based array with the following information:
;                  |0 - Object of the Slide where the text has been found
;                  |1 - Object of the Shape where the text has been found
;                  |2 - Object of the TextRange where the text has been found
;                  Failure - 0 and sets @error.
;                  |1 - $oPresentation is not an object or not a presentation object
;                  |2 - $sFindText is empty
;                  |3 - Error occurred creating the SlideRange from $vSlides. @extended is set to the error code returned by _PPT_SlideRangeSet
;                  |4 - Error occurred creating the ShapeRange from $vShapes. @extended is set to the error code returned by _PPT_ShapeRangeSet
;                  |5 - Number of Slides is > 1 but $vShapes is not one of the allowed values: 0, >0 or a string
; Author ........: water
; Modified ......:
; Remarks .......: Parameter $vSlides: See _PPT_SlideRangeSet for the format of this parameter
;                  Parameter $vShapes:
;                    If Number of Slides is = 1: All values for _PPT_ShapeRangeSet are valid. See _PPT_ShapeRangeSet for the format of this parameter
;                    If Number of Slides is > 1: only 0 (all Shapes), integer (ID of the Shape) or a string (Name of the Shape) are valid
;+
;                  While looping through the Shapes of a Slide errors are ignored and processing continues with the next Shape.
; Related .......:
; Link ..........: https://www.thespreadsheetguru.com/the-code-vault/find-and-replace-all-powerpoint-vba-macro
; Example .......: Yes
; ===============================================================================================================================
Func _PPT_TextFind($oPresentation, $sFindText, $vSlides = Default, $vShapes = Default, $iOccurrence = Default, $bMatchCase = Default, $bWholeWords = Default)
    Local $oSlide, $oSlideRange, $oShape, $oShapeRange, $oShapeTextFrame, $oTextRange, $sShapeText, $oTempText, $iFindCountTotal = 0, $iFindCount = 0, $aResult[10000][3]
    If $bMatchCase = Default Then $bMatchCase = False
    If $bWholeWords = Default Then $bWholeWords = False
    If $iOccurrence = Default Then $iOccurrence = 0
    If $vSlides = Default Then $vSlides = 0
    If $vShapes = Default Then $vShapes = 0
    If Not IsObj($oPresentation) Or ObjName($oPresentation, 1) <> "_Presentation" Then Return SetError(1, 0, 0)
    If StringStripWS($sFindText, $STR_STRIPALL) = "" Then Return SetError(2, 0, 0)
    $oSlideRange = _PPT_SlideRangeSet($oPresentation, $vSlides)
    If @error Then Return SetError(3, @error, 0)
    If $oSlideRange.Count > 1 And _
            Not ($vShapes = 0 Or $vShapes > 0 Or IsString($vShapes)) Then     ; Check allowed values: 0 (all Slides), integer (single Slide), String (SlideName)
        Return SetError(5, 0, 0)
    EndIf
    ; Loop through the specified Slides
    For $oSlide In $oSlideRange
        ; Get the ShapeRange for every specified Slide
        $oShapeRange = _PPT_ShapeRangeSet($oPresentation, $oSlide, $vShapes)
        If @error Then Return SetError(4, @error, 0)
        For $oShape In $oShapeRange
            ; Get the TextFrame. If the Shape contains no TextFrame continue with the next Shape
            $oShapeTextFrame = $oShape.TextFrame
            If @error Then ContinueLoop
            ; Get TextRange of the TextFrame. If there is an error continue with the next Shape
            $oTextRange = $oShapeTextFrame.TextRange
            If @error Then ContinueLoop
            ; Get the Text of the TextRange
            $sShapeText = $oTextRange.Text
            If @error Then ContinueLoop
            ; Ensure there is text to search through
            If $sShapeText <> "" Then
                ; Find first instance of "FindText"
            ;   $oTempText = $oTextRange.Replace($sFindText, $sReplaceText, Default, $bMatchCase, $bWholeWords)
                $oTempText = $oTextRange.Find($sFindText, Default, $bMatchCase, $bWholeWords)
                If IsObj($oTempText) Then
                    $aResult[$iFindCountTotal][0] = $oSlide
                    $aResult[$iFindCountTotal][1] = $oShape
                    $aResult[$iFindCountTotal][2] = $oTempText
                    $iFindCountTotal += 1
                    $iFindCount = 1
                EndIf
                ; Find any additional instances of "Findtext" (if exists)
                While IsObj($oTempText)
                    If $iFindCount >= $iOccurrence Then ExitLoop
                    $oTextRange = $oTextRange.Characters($oTempText.Start + $oTempText.Length, $oTextRange.Length)
                ;   $oTempText = $oTextRange.Replace($sFindText, $sReplaceText, Default, $bMatchCase, $bWholeWords)
                    $oTempText = $oTextRange.Find($sFindText, Default, $bMatchCase, $bWholeWords)
                    $aResult[$iFindCountTotal][0] = $oSlide
                    $aResult[$iFindCountTotal][1] = $oShape
                    $aResult[$iFindCountTotal][2] = $oTempText
                    If IsObj($oTempText) Then
                        $iFindCountTotal += 1
                        $iFindCount += 1
                    EndIf
                WEnd
            EndIf
        Next
    Next
    ReDim $aResult[$iFindCountTotal][UBound($iFindCountTotal, 2)]
    Return $aResult
EndFunc   ;==>_PPT_TextFind

 

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.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 (NEW 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 month later...

I am looking for a powerpoint function to change the presentation from 4:3 to 16:9.  I thought I would find it within the PowerPoint.au3 but can't seem to find an routine that has the ability to change this for the presentation.  Help?

Thanks in advance, Rich

Link to comment
Share on other sites

Never tried it myself so I had to ask Google. At the moment I have no access to a Windows PC with PPT, hence the following code is untested:

Global Const $PpSlideSizeOnScreen = 1
Global Const $PpSlideSizeOnScreen16x10 = 16
Global Const $PpSlideSizeOnScreen16x9 = 15

$oPresentation.PageSetup.SlideSize = $PpSlideSizeOnScreen16x9

 

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.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 (NEW 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

Getting an error.  It seems like it wants me to build a complete new object and then update the values within the new object?  Am I mis-intrepreting the error?

 

"C:\PowerPoint Converter\My Code to fix slides.au3" (13) : ==> Variable must be of type "Object".:
$presentation.PageSetup.SlideSize = $PpSlideSizeOnScreen16x9
$presentation^ ERROR
->11:20:37 AutoIt3.exe ended.rc:1
+>11:20:37 AutoIt3Wrapper Finished.

Link to comment
Share on other sites

$presentation has to be the PowerPoint Presentation object. In my example I use $oPresentation.
As you didn't post your script I only can guess that you do not use $presentation when opening an existing or creating a new presentation.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.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 (NEW 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

#include <Constants.au3>
#Include <PowerPoint.au3>

Global $presentation
Global Const $PpSlideSizeOnScreen = 1
Global Const $PpSlideSizeOnScreen16x10 = 16
Global Const $PpSlideSizeOnScreen16x9 = 15

_PPT_PresentationOpen($presentation, "C:\PowerPoint Converter\4by3.pptx")
MsgBox($MB_SYSTEMMODAL, "OUTPUT", "Opening Pres" & @CRLF )

$presentation.PageSetup.SlideSize = $PpSlideSizeOnScreen16x9
MsgBox($MB_SYSTEMMODAL, "OUTPUT", "Setting Slide Size" & @CRLF )

_PPT_PresentationSaveAs($presentation,"C:\PowerPoint Converter\16x9.pptx")
MsgBox($MB_SYSTEMMODAL, "OUTPUT", "Doing a Save AS" & @CRLF )

_PPT_PresentationClose($presentation)
MsgBox($MB_SYSTEMMODAL, "OUTPUT", "Closing File" & @CRLF )

Link to comment
Share on other sites

"C:\PowerPoint Converter\My Code to fix slides.au3" (13) : ==> Variable must be of type "Object".:
$presentation.PageSetup.SlideSize = $PpSlideSizeOnScreen16x9
$presentation^ ERROR
->16:54:39 AutoIt3.exe ended.rc:1
+>16:54:39 AutoIt3Wrapper Finished.
>Exit code: 1    Time: 3.112

Link to comment
Share on other sites

Thanks for helping BTW.  I appreciate it!.  I am new to AutoIT. 

One additional assumption.  When I "open" up an existing powerpoint, the $presentation variable I am using is just a pointer to the file.  

What I was thinking I would need to do is "read in" the slides and then manipulate each accordingly. 

I probably don't fully understand the AUTOIT language.

Edited by alexanr1
Link to comment
Share on other sites

I see (at least) two problems:

  • You do not call _PPT_Open to start the PowerPoint application (or to connect to an already running instance)
  • You do not store the presentation object returned by _PPT_PresentationOpen in variable $presentation

Please have a look at example script _PPT_PresentationOpen.au3 that comes with the UDF.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.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 (NEW 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

Got it to work!   My only new challenge is the image on the Powerpoint slide is not being maximized.  Curious if that is a paramater I can pass?

 

Here is the test code BTW...

--------------------------------------------------------

#Include <PowerPoint.au3>
#include <Constants.au3>
#include <File.au3>

Global $oPPT = _PPT_Open()
Global $sPresentation = "C:\PowerPoint Converter\4by3.pptx"
Global Const $PpSlideSizeOnScreen = 1
Global Const $PpSlideSizeOnScreen16x10 = 16
Global Const $PpSlideSizeOnScreen16x9 = 15

ConsoleWrite ("@error=" & @error & @CRLF )
Global $oPresentation = _PPT_PresentationOpen($oPPT, $sPresentation, True)
ConsoleWrite ("Opening Presentation" & @CRLF )
ConsoleWrite ("@error=" & @error & @CRLF )
if @error then ConsoleWrite ("Failed to Open Presentation"& @CRLF )

$oPresentation.PageSetup.SlideSize = $PpSlideSizeOnScreen16x9

_PPT_PresentationSaveAs($oPresentation, "C:\PowerPoint Converter\16by9",$ppSaveAsPresentation, True)
ConsoleWrite ("Doing a Save AS" & @CRLF )
ConsoleWrite ("@error=" & @error & @CRLF  )

_PPT_PresentationClose($oPresentation)
ConsoleWrite ("Closing File" & @CRLF )
ConsoleWrite ("@error=" & @error & @CRLF  )

Link to comment
Share on other sites

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.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 (NEW 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

×
×
  • Create New...