Insert Excel picture into Powerpoint place holder in slide

tiredofit

Well-known Member
Joined
Apr 11, 2013
Messages
1,924
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
I am trying to copy a picture in Excel and paste it into a placeholder in a slide in Powerpoint.

Code:
    Dim ppApp As PowerPoint.Application

    Set ppApp = New PowerPoint.Application

    Sheet1.Cells(1, 1).Select

    Selection.CopyPicture Appearance:=xlScreen, Format:=xlPicture

    ppApp.Presentations(1).Slides(2).Shapes.Range(Array("Placeholder 1")).TextFrame.TextRange.PasteSpecial ppPasteBitmap

but it fails on the last line, possibly because it's expecting text to be pasted, instead of a picture.

How can I amend my code to make it work?

Thanks
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
Your code create a new PP Application; then you address a Placehord in Presentations(1).Slides(2). Does a Presentation#1 exists? With a Slide#2? Having a placeholder named "Placeholder 1"?
Or did you forgot opening the target presentation?
 
Upvote 0
Your code create a new PP Application; then you address a Placehord in Presentations(1).Slides(2). Does a Presentation#1 exists? With a Slide#2? Having a placeholder named "Placeholder 1"?
Or did you forgot opening the target presentation?
Yes, all the elements exist.

What do you mean by:

then you address a Placehord in Presentations(1).Slides(2)
 
Upvote 0
Hummm...
Yes, all the elements exist.
You mean that when you start your Powerpoint (Set ppApp = New PowerPoint.Application) magically a presentation with two slides and a "Placeholder" popups in it? I'm doubtful

What do you mean by:
then you address a Placehord in Presentations(1).Slides(2)
I was pointing that, after a new Powerpoint is started, hardly a presentation with two slides and a "placeholder" in it is within the application.

My position is that after your PowerPoint application starts, it is empty; you need to open a presentation before beeing able to work on it
And, btw, which is the error message that is shown when the instruction fails?
 
Upvote 0
Hummm...

You mean that when you start your Powerpoint (Set ppApp = New PowerPoint.Application) magically a presentation with two slides and a "Placeholder" popups in it? I'm doubtful


I was pointing that, after a new Powerpoint is started, hardly a presentation with two slides and a "placeholder" in it is within the application.

My position is that after your PowerPoint application starts, it is empty; you need to open a presentation before beeing able to work on it
And, btw, which is the error message that is shown when the instruction fails?
This is the full code:

Code:
    Dim ppApp As PowerPoint.Application

    Dim ppPres As PowerPoint.Presentation

    Dim ppSlide As PowerPoint.Slide

    Set ppApp = New PowerPoint.Application

    ppApp.Visible = msoCTrue

    ppApp.Presentations.Open ("C:\Documents\MyPP.pptx")

    Sheet1.Cells(1, 1).Select

    Selection.CopyPicture Appearance:=xlScreen, Format:=xlPicture

    ppApp.Presentations(1).Slides(2).Shapes.Range(Array("Placeholder 1")).TextFrame.TextRange.PasteSpecial ppPasteBitmap

The error occurs on this line:

Code:
ppApp.Presentations(1).Slides(2).Shapes.Range(Array("Placeholder 1")).TextFrame.TextRange.PasteSpecial ppPasteBitmap

with the message:

Code:
TextRange (unknown member) : Invalid enumeration value
 
Upvote 0
1) You correctly debugged that a bitmap cannot be pasted to a TextFrame.TextRange

2) Sorry, I was not able to create a workable situation like the one you have (probably I misunderstood Microsoft instructions for dealing with Placeholder)
The only thing I can suggest is trying to adapt the following instruction to your situation:
VBA Code:
ppApp.Presentations(1).Slides(2).Shapes.Range(Array("Placeholder 1")).Fill.UserPicture ("D:\DImages\PictureName.jpg")
HOWEVER this implies that the placeholder is set to hold an image, and that you have to save your area as a real file; if you do a Google search using the string save range as image site:mrexcel.com you will see how this is normally done (in several flavors)

But it seems that you need to pass a single cell content to the placeholder, so maybe you can cope with the current placeholder using
VBA Code:
ppApp.Presentations(1).Slides(2).Shapes.Range(Array("Placeholder 1")).TextFrame.TextRange.Text = Sheet1.Cells(1, 1).Value
 
Upvote 0
1) You correctly debugged that a bitmap cannot be pasted to a TextFrame.TextRange

2) Sorry, I was not able to create a workable situation like the one you have (probably I misunderstood Microsoft instructions for dealing with Placeholder)
The only thing I can suggest is trying to adapt the following instruction to your situation:
VBA Code:
ppApp.Presentations(1).Slides(2).Shapes.Range(Array("Placeholder 1")).Fill.UserPicture ("D:\DImages\PictureName.jpg")
HOWEVER this implies that the placeholder is set to hold an image, and that you have to save your area as a real file; if you do a Google search using the string save range as image site:mrexcel.com you will see how this is normally done (in several flavors)

But it seems that you need to pass a single cell content to the placeholder, so maybe you can cope with the current placeholder using
VBA Code:
ppApp.Presentations(1).Slides(2).Shapes.Range(Array("Placeholder 1")).TextFrame.TextRange.Text = Sheet1.Cells(1, 1).Value
Thanks for suggestions.

I think it less of a headache if I do away with the Placeholder and instead, just paste the picture onto the slide, then reposition it to where the Placeholder was.
 
Upvote 0

Forum statistics

Threads
1,223,876
Messages
6,175,123
Members
452,614
Latest member
MRSWIN2709

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top