Search code examples
excelvbaalignmentpowerpoint

Align pictures on Powerpoint


I currently am creating a macro that will take a excel file and put it contents into a PowerPoint. I am having trouble aligning the picture I just copy and pasted from excel into the PowerPoint. Below is the code I am using to paste the picture and keep receiving the error that "The item with the specified name wasn't found." I am wondering if this is because the macro is ran from Excel and not PowerPoint?

     Sheets("Bay du Nord").Range("E3:P9").CopyPicture _
Appearance:=xlScreen, Format:=xlPicture

Slide2.Select
Slide2.Shapes.Paste.Name = "SamplePic"



Set Shp1 = ActiveSheet.Shapes("Textbox 13")
Set shp2 = ActiveSheet.Shapes("SamplePic")

shp2.Top = Shp1.Top

Solution

  • I'm assuming that "TextBox 3" is located on your slide, not on your worksheet, and that you want to align the pasted shape with "TextBox 3" on your slide. If so, try the following:

    Sheets("Bay du Nord").Range("E3:P9").CopyPicture _
        Appearance:=xlScreen, Format:=xlPicture
    
    Set shp1 = Slide2.Shapes("TextBox 3")
    
    With Slide2
        .Shapes.Paste.Name = "SamplePic"
        With .Shapes(.Shapes.Count)
            .Top = shp1.Top
        End With
    End With