Function Reference

_PPT_TextFindReplace

Find & replace text on a single or selected slides.

#Include <PowerPoint.au3>
_PPT_TextFindReplace($oPresentation, $sFindText, $sReplaceText[, $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.
$sReplaceText The replacement text. To delete found text use an empty string ("").
$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 replace $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 Value

Success: 1, @extended holds the number of successfully performed replacements.
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

 

Remarks

With this function you can delete a single Shape from multiple Slides or multiple Shapes from a single Slide.

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

 

See Also

https://www.thespreadsheetguru.com/the-code-vault/find-and-replace-all-powerpoint-vba-macro

 

Example


#AutoIt3Wrapper_AU3Check_Parameters= -d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#AutoIt3Wrapper_AU3Check_Stop_OnWarning=N
#include <PowerPoint.au3>
#include <MsgBoxConstants.au3>

; *************************************************
; Create application object and open a presentation
; *************************************************
Global $oPPT = _PPT_Open()
If @error Then Exit MsgBox($MB_ICONERROR, "PowerPoint UDF: _PPT_TextFindReplace Example", "Error creating the PowerPoint application object." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
; Open presentation
Global $sPresentation = @ScriptDir & "\Presentation1.pptx"
Global $oPresentation = _PPT_PresentationOpen($oPPT, $sPresentation)
If @error Then
    MsgBox($MB_ICONERROR, "PowerPoint UDF: _PPT_TextFindReplace Example", "Error opening presentation '" & $sPresentation & "'." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
    _PPT_Close($oPPT)
    Exit
EndIf

; ***********************************************************************************************
; Replace Text ...
; ***********************************************************************************************
MsgBox($MB_ICONINFORMATION, "PowerPoint UDF: _PPT_TextFindReplace Example 1", "Presentation before Replace!", 5)
Global $sFindText = "Test", $sReplaceText = "xyz"
_PPT_TextFindReplace($oPresentation, $sFindText, $sReplaceText, "1-2", 0, 1)
If @error Then Exit MsgBox($MB_ICONERROR, "PowerPoint UDF: _PPT_TextFindReplace Example 1", "Error replacing text." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
MsgBox($MB_ICONINFORMATION, "PowerPoint UDF: _PPT_TextFindReplace Example 1", "Text replaced " & @extended & " times in the specified range!")