Jump to content

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

Link to comment
Share on other sites

  • Replies 41
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

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

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

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 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

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)

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

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 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

$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 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

Can you please post the code you run?
 

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

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 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

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

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

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)

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...