Jump to content
Sign in to follow this  
beisaikong

add a picture to a powerpoint slide

Recommended Posts

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

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


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2020-10-10 - Version 1.5.2.1) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2020-06-30 - Version 1.6.2.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (NEW 2020-06-27 - Version 1.3.2.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
Task Scheduler (2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - Wiki

Tutorials:
ADO - Wiki, WebDriver - Wiki

 

Share this post


Link to post
Share on other sites

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 2020-10-10 - Version 1.5.2.1) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2020-06-30 - Version 1.6.2.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (NEW 2020-06-27 - Version 1.3.2.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
Task Scheduler (2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - Wiki

Tutorials:
ADO - Wiki, WebDriver - Wiki

 

Share this post


Link to post
Share on other sites

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

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 2020-10-10 - Version 1.5.2.1) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2020-06-30 - Version 1.6.2.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (NEW 2020-06-27 - Version 1.3.2.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
Task Scheduler (2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - Wiki

Tutorials:
ADO - Wiki, WebDriver - Wiki

 

Share this post


Link to post
Share on other sites

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

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 2020-10-10 - Version 1.5.2.1) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2020-06-30 - Version 1.6.2.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (NEW 2020-06-27 - Version 1.3.2.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
Task Scheduler (2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - Wiki

Tutorials:
ADO - Wiki, WebDriver - Wiki

 

Share this post


Link to post
Share on other sites
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 2020-10-10 - Version 1.5.2.1) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2020-06-30 - Version 1.6.2.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (NEW 2020-06-27 - Version 1.3.2.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
Task Scheduler (2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - Wiki

Tutorials:
ADO - Wiki, WebDriver - Wiki

 

Share this post


Link to post
Share on other sites

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

$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 2020-10-10 - Version 1.5.2.1) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2020-06-30 - Version 1.6.2.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (NEW 2020-06-27 - Version 1.3.2.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
Task Scheduler (2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - Wiki

Tutorials:
ADO - Wiki, WebDriver - Wiki

 

Share this post


Link to post
Share on other sites

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

Can you please post the code you run?
 


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2020-10-10 - Version 1.5.2.1) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2020-06-30 - Version 1.6.2.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (NEW 2020-06-27 - Version 1.3.2.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
Task Scheduler (2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - Wiki

Tutorials:
ADO - Wiki, WebDriver - Wiki

 

Share this post


Link to post
Share on other sites

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 2020-10-10 - Version 1.5.2.1) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2020-06-30 - Version 1.6.2.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (NEW 2020-06-27 - Version 1.3.2.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
Task Scheduler (2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - Wiki

Tutorials:
ADO - Wiki, WebDriver - Wiki

 

Share this post


Link to post
Share on other sites

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

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 2020-10-10 - Version 1.5.2.1) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2020-06-30 - Version 1.6.2.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (NEW 2020-06-27 - Version 1.3.2.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
Task Scheduler (2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - Wiki

Tutorials:
ADO - Wiki, WebDriver - Wiki

 

Share this post


Link to post
Share on other sites

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

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


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2020-10-10 - Version 1.5.2.1) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2020-06-30 - Version 1.6.2.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (NEW 2020-06-27 - Version 1.3.2.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
Task Scheduler (2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - Wiki

Tutorials:
ADO - Wiki, WebDriver - 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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...