Function Reference

_PPT_ShapeAdd

Add a Shape to a single or multiple Slides.

#Include <PowerPoint.au3>
_PPT_ShapeAdd($oPresentation, $vSlides, $iShapeType, $iX1, $iY1, $iX2, $iY2[, $vP1 = Default[, $vP2 = Default[, $vP3 = Default[, $vP4 = Default[, $vP5 = Default]]]]])

 

Parameters

$oPresentation Object of the presentation to process.
$vSlides Slides to process. See Remarks.
$iShapeType Constant from the MsoShapeType enumeration representing the type of Shape to add.
$iX1 The position (in Points) of the left edge of the Shape relative to the left edge of the Slide. See Remarks.
$iY1 The position (in Points) of the top edge of the Shape relative to the left edge of the Slide. See Remarks.
$iX2 The Width (in Points) of the Shape. See Remarks.
$iY2 The Height (in Points) of the Shape. See Remarks.
$vP1 [optional] Additional parameter for the Addxxxx method of the Shapes collection. See Remarks.
$vP2 [optional] Additional parameter for the Addxxxx method of the Shapes collection. See Remarks.
$vP3 [optional] Additional parameter for the Addxxxx method of the Shapes collection. See Remarks.
$vP4 [optional] Additional parameter for the Addxxxx method of the Shapes collection. See Remarks.
$vP5 [optional] Additional parameter for the Addxxxx method of the Shapes collection. See Remarks.

 

Return Value

Success: zero-based one dimensional array with a Shape object for each Slide in the SlideRange
Failure: 0 and sets @error.
    1 - $oPresentation is not an object or not a presentation object
    2 - Error occurred creating the SlideRange from $vSlides. @extended is set to the error code returned by _PPT_SlideRangeSet
    3 - Error creating the Shape. @extended is set to the COM error code
    4 - $iShapeType is invalid

 

Remarks

In the following table you find the parameters to use based on the ShapeType you want to create:
SHAPETYPE $iX1 $iY1 $iX2 $iY2 $vP1 $vP2 $vP3 $vP4
$MsoChart Left Top Width Height Style Type NewLayout
$MsoLine BeginX BeginY EndX EndY
$MsoPicture Left Top Width Height FileName LinkToFile SaveWithDocument Compress
$MsoTable Left Top Width Height NumRows NumColumns
$MsoTextBox Left Top Width Height Orientation

When you pass Default for $iX1, $iY2, $iX2 or $iY2 then PowerPoint decides where to place the Shape.

For details please check the MS documentation:
$MsoChart https://docs.microsoft.com/en-us/office/vba/api/powerpoint.shapes.addchart2
$MsoLine https://docs.microsoft.com/en-us/office/vba/api/powerpoint.shapes.addline
$MsoPicture https://docs.microsoft.com/en-us/office/vba/api/powerpoint.shapes.addpicture2
$MsoTable https://docs.microsoft.com/en-us/office/vba/api/powerpoint.shapes.addtable
$MsoTextBox https://docs.microsoft.com/en-us/office/vba/api/powerpoint.shapes.addtextbox

 

Related

_PPT_ShapeDelete

 

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>

Global $aShape
; *************************************************
; Create application object and open a presentation
; *************************************************
Global $oPPT = _PPT_Open()
If @error Then Exit MsgBox($MB_ICONERROR, "PowerPoint UDF: _PPT_ShapeAdd 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_ShapeAdd Example", "Error opening presentation '" & $sPresentation & "'." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
    _PPT_Close($oPPT)
    Exit
EndIf

; ***********************************************************************************************
; Example 1
; Add a line to Slides 1 and 2
; See: https://docs.microsoft.com/en-us/office/vba/api/powerpoint.shapes.addline
; ***********************************************************************************************
_PPT_ShapeAdd($oPresentation, "1-2", $MsoLine, 10, 10, 250, 250)
If @error Then Exit MsgBox($MB_ICONERROR, "PowerPoint UDF: _PPT_ShapeAdd Example 1", "Error adding Shape!" & @CRLF & "@error = " & @error & ", @extended = " & @extended)
MsgBox($MB_ICONINFORMATION, "PowerPoint UDF: _PPT_ShapeAdd Example 1", "Line Shape added to Slides 1 and 2.")

; ***********************************************************************************************
; Example 2
; Add a picture to Slide 3
; See: https://docs.microsoft.com/en-us/office/vba/api/powerpoint.shapes.addpicture2
; ***********************************************************************************************
_PPT_ShapeAdd($oPresentation, 3, $MsoPicture, 10, 280, 250, 250, @ScriptDir & "\Microsoft_PowerPoint_2013_logo.png", False, True, 1)
If @error Then Exit MsgBox($MB_ICONERROR, "PowerPoint UDF: _PPT_ShapeAdd Example 2", "Error adding Shape!" & @CRLF & "@error = " & @error & ", @extended = " & @extended)
MsgBox($MB_ICONINFORMATION, "PowerPoint UDF: _PPT_ShapeAdd Example 2", "Picture Shape added to Slide 3.")

; ***********************************************************************************************
; Example 3
; Add a TextBox to Slide 3
; See: https://docs.microsoft.com/en-us/office/vba/api/powerpoint.shapes.addtextbox
; ***********************************************************************************************
$aShape = _PPT_ShapeAdd($oPresentation, 3, $MsoTextBox, 300, 280, 250, 250, 1)
If @error Then Exit MsgBox($MB_ICONERROR, "PowerPoint UDF: _PPT_ShapeAdd Example 3", "Error adding Shape!" & @CRLF & "@error = " & @error & ", @extended = " & @extended)
Global $oShapeTextFrame = $aShape[0].TextFrame
Global $oTextRange = $oShapeTextFrame.TextRange
$oTextRange.Text = "TextBox Shape"
$aShape[0].ShapeStyle = 10016
MsgBox($MB_ICONINFORMATION, "PowerPoint UDF: _PPT_ShapeAdd Example 3", "TextBox Shape added to Slide 3.")

; ***********************************************************************************************
; Example 4
; Add a Table to Slide 2
; See: https://docs.microsoft.com/en-us/office/vba/api/powerpoint.shapes.addtable
; ***********************************************************************************************
_PPT_ShapeAdd($oPresentation, 2, $MsoTable, 100, 300, 250, 70, 3, 4)
If @error Then Exit MsgBox($MB_ICONERROR, "PowerPoint UDF: _PPT_ShapeAdd Example 4", "Error adding Shape!" & @CRLF & "@error = " & @error & ", @extended = " & @extended)
MsgBox($MB_ICONINFORMATION, "PowerPoint UDF: _PPT_ShapeAdd Example 4", "Table Shape added to Slide 2.")

; ***********************************************************************************************
; Example 5
; Add a Chart to Slide 2
; See: https://docs.microsoft.com/en-us/office/vba/api/powerpoint.shapes.addchart2
; ***********************************************************************************************
_PPT_ShapeAdd($oPresentation, 2, $MsoChart, 300, 20, 250, 150, -1, -4102, 0)
If @error Then Exit MsgBox($MB_ICONERROR, "PowerPoint UDF: _PPT_ShapeAdd Example 5", "Error adding Shape!" & @CRLF & "@error = " & @error & ", @extended = " & @extended)
MsgBox($MB_ICONINFORMATION, "PowerPoint UDF: _PPT_ShapeAdd Example 5", "Chart Shape added to Slide 2.")