Jump to content
beisaikong

add a picture to a powerpoint slide

Recommended Posts

beisaikong

hi

i was writing a simple code below

#include-once
#include <StringConstants.au3>
#include <PowerPointConstants.au3>
#include <Constants.au3>

#Region Include
#include <PowerPoint.au3>

$objPPT = _PPT_Open(True)

$objPres = _PPT_PresentationOpen($objPPT, "H:\Auto\Test.ppt")

MouseClick($MOUSE_CLICK_LEFT,1000,600,1)

Send("{DEL 1}")

MouseClick($MOUSE_CLICK_LEFT,1000,600,1)

$objTest = _PPT_SlideAddPicture($objPres,"H:\Auto\_MG_7551.jpg",0,0,100,100)

 

the last part of adding a picture did not work, there is no error and nothing happen. anyone can help ?

regards

beisaikong

Share this post


Link to post
Share on other sites
water

What's the value of @error and  @extended after calling _PPT_SlideAddPicture?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
beisaikong

@error shows 3 and @extended shows 0. what does it means ?

Share this post


Link to post
Share on other sites
water

Seems you are using this PowerPoint UDF:

@error 3 means, that one of the parameters left, top, width, height is missing or wrong.

Func _PPT_SlideAddPicture(ByRef $obj, $filepath, $left = 0, $top = 0, $width = 100, $height = 100)

But the code you post seems to be correct :huh:
Do you really run the code you posted?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
beisaikong

the udf you mention is my powerpoint1.au3. this udf have the slideaddpicture. the previous code, i just copy this slideaddpicture function into the powerpoint.au3

same results whether i use either udf

#include-once
#include <StringConstants.au3>
;#include <PowerPointConstants.au3>
#include <Constants.au3>

#Region Include
#include <PowerPoint1.au3>

$objPPT = _PPT_PowerPointApp(1)

$objPres = _PPT_PresentationOpen($objPPT, "H:\Auto\Test.ppt")

MouseClick($MOUSE_CLICK_LEFT,1000,600,1)

Send("{DEL 1}")

MouseClick($MOUSE_CLICK_LEFT,1000,600,1)

$objTest = _PPT_SlideAddPicture($objPPT,"H:\Auto\_MG_7551.jpg",0,5,105,100)

Share this post


Link to post
Share on other sites
water

Mixing two UDFs is not supported and errors are hard to find.
But I think the problem is caused by the following fact:
Neither the PowerPoint application object (referenced by $objPPT in your script) nor the presentation object (referenced by $objPres) offers a shape object as being used in function _PPT_SlideAddPicture.
You need to access a slide and pass the slide object to function _PPT_SlideAddPicture.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
beisaikong

i can use just one udf. i had the same suspicion but i already have an existing presentation with 1 slide. i do not see any function in the udf which will just assess a slide ?

Share this post


Link to post
Share on other sites
water

I think it should work when you specify the slide object:

$objTest = _PPT_SlideAddPicture($objPres.Slides(1), "H:\Auto\_MG_7551.jpg", 0, 5, 105, 100)

Should add the picture to slide 1.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
beisaikong

Give me this error. error: _PPT_SlideAddPicture() called with Const or expression on ByRef-param(s).

Share this post


Link to post
Share on other sites
beisaikong

i did some testing and with new presentation and new slide, it works. Opening an existing presentation need some tweaking it seems.

Share this post


Link to post
Share on other sites
water
5 minutes ago, beisaikong said:

Give me this error. error: _PPT_SlideAddPicture() called with Const or expression on ByRef-param(s).

Then pass the slide object as a variable:

$objSlide = $objPres.Slides(1)
$objTest = _PPT_SlideAddPicture($objSlide, "H:\Auto\_MG_7551.jpg", 0, 5, 105, 100)

 


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
beisaikong

now it worked. thanks

how do you know that .slides is like a property of $objPres ?

since now $objTest is a picture object, how can i send the picture to the background ?

Share this post


Link to post
Share on other sites
water

$objTest is a Shape object. The following method allows to move a shape to the background: https://msdn.microsoft.com/en-us/library/ff744516(v=office.14).aspx


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
beisaikong

can't seems to use the $objTest.ZOrderPosition or $objTest.ZOrder direct off the shape object. it is not doing anything. 

any thoughts ?

Share this post


Link to post
Share on other sites
water

Can you please post the code you run?
 


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
water

The MSOZOrderCmd enumeration can be found here: https://msdn.microsoft.com/en-us/library/aa432726(v=office.12).aspx


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
beisaikong

here is the code


#include <StringConstants.au3>
#include <Constants.au3>
#include <PowerPoint1.au3>
#include <misc.au3>


$objPPT = _PPT_PowerPointApp()

$objPres = _PPT_PresentationOpen($objPPT, "H:\Auto\Test.ppt")

$objSlide = $objPres.Slides(1)

$objPicture = _PPT_SlideAddPicture($objSlide, "H:\Auto\MG_7551.jpg",-1,-1,721,542)

$objPicture.ZOrder = 1

Share this post


Link to post
Share on other sites
water

The function from the old PowerPoint UDF does not return the Shapes object. So you can't access $objPicture in your script.

This code does not rely on the old UDF and works:

#include <PowerPoint.au3>

$oPPT = _PPT_Open()
$oPres = _PPT_PresentationOpen($oPPT, @ScriptDir & "\Presentation1.pptx")
$oSlide = $oPres.Slides(1)
$oPicture = _PPT_SlideAddPicture($oSlide, @ScriptDir & "\Microsoft_PowerPoint_2013_logo.png", -1, -1, 721, 542)
$oPicture.ZOrder(1)

Func _PPT_SlideAddPicture(ByRef $obj, $filepath, $left = 0, $top = 0, $width = 100, $height = 100)
    If IsObj($obj) <> 1 Then
        SetError(1)
        Return 0
    ElseIf FileExists($filepath) <> 1 Then
        SetError(2)
        Return 2 ;file does not exist
    ElseIf $left = "" Or $top = "" Or $width = "" Or $height = "" Then
        SetError(3)
        Return 3
    ElseIf IsInt($left+$top+$width+$height) <> 1 Then
        SetError(4)
        Return 4 ;All parameters have to be integer
    Else
        Return $obj.Shapes.AddPicture($filepath, 0, 1,150, 150, 500, 350)
    Endif
EndFunc

 


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
beisaikong

try the code you suggested. the newly added picture was not send to back. i am using powerpoint 2010.


#include <StringConstants.au3>
#include <Constants.au3>
#include <PowerPoint.au3>
#include <misc.au3>


$oPPT = _PPT_Open()
$oPres = _PPT_PresentationOpen($oPPT, "H:\Auto\Test.ppt")
MouseClick($MOUSE_CLICK_LEFT,1000,600,1)
Send("{DEL 1}")
$oSlide = $oPres.Slides(1)
$oPicture = _PPT_SlideAddPicture($oSlide, "H:\Auto\MG_7551.jpg", -1, -1, 721, 542)
$oPicture.ZOrder(1)

Share this post


Link to post
Share on other sites
water

What do you mean with "send to background"? Should the picture become invisible?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
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

×