none
Power Point 2010 insert picture to chart RRS feed

  • Question

  • Hi,

    I am trying to insert a banner picture inside the top of the chart area. I thought I can do it via "Slide.Shapes.Chart.Shapes.AddPicture" function, but I was getting this error: Run-time error '-2147467259(80004005)': Method 'AddPicture' of object 'Shape' failed.

    However, if I did it with the Power Point interface, by selecting the chart, then do Insert Picture, it did insert the banner perfectly.  see below image, I added the top gray banner using the Insert Picture on the PPT interface.

     

    Why my code doesn't work? 

    Can someone help?

    my code is like this:

                                 

     For Each sld In ActivePresentation.Slides
                For Each shp In sld.Shapes
                    If shp.HasChart Then
            Set oChart = shp.Chart
            If oChart.ChartType = 51 Then

          

     With oChart
                .HasTitle = False
                .PlotArea.Height = .PlotArea.Height - (BannerHeight + BannerPaddingTop)
                .PlotArea.Format.Line.Visible = msoFalse
                .PlotArea.Top = BannerHeight + 5
                'MsgBox "New plotarea top " & .PlotArea.Top
               .Shapes.AddPicture filename:=BannerPath, LinkToFile:=msoTrue, SaveWithDocument:=msoTrue, Left:=BannerPaddingLeft, Top:=BannerPaddingTop, Width:=BannerWidth, Height:=BannerHeight

    Thanks, Chris

    Monday, October 10, 2016 10:37 PM

All replies

  • Hi Chris,

    I made a test with PopwerPoint 2013, and I could reproduce your issue.

    I try to add a shape, and it works. For a workaround, I would suggest you add a shape first, and then fill the shape with image. Here is a simple code:

    Sub insertShape()
    Dim oChart As Chart
    Dim sId As Slide
    Dim shp As Shape
    Dim simg As Shape
    For Each sId In ActivePresentation.Slides
        For Each shp In sId.Shapes
            If shp.HasChart Then
                Set oChart = shp.Chart
                Set simg = oChart.Shapes.AddShape(Type:=msoShapeRectangle, _
        Left:=10, Top:=10, Width:=100, Height:=200)
                simg.Fill.UserPicture "C:\Users\xx\Desktop\test.png"
            End If
        Next shp
    Next sId
    End Sub

    For another way, I would suggest you add shapes to slide, and then reset the location of the picture. Here is a simple code:

    sId.Shapes.AddPicture "C:\Users\xx\Desktop\xx.png", LinkToFile:=MsoTriState.msoTrue, SaveWithDocument:=MsoTriState.msoFalse, Left:=10, Top:=10, Width:=100, Height:=50

    Best Regards,

    Edward


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.



    Wednesday, October 12, 2016 6:08 AM
  • Hi Edward,

    I did try the method that you provided as a test by simply copy and paste to PPT VBA, only thing I changed is the location of the jpg file.

    So I created a column chart and ran the macro, it did create the shape but I got this message when it tried to insert the picture:

     

    any suggests what should I do?

    Thanks,

    Chris

    Thursday, October 13, 2016 11:38 PM
  • Hi Chris,

    Currently, I do not have Office 2010, I made a test with Office 2013 and Office 2007, it works.

    To check whether your product is broken, I suggest you follow Select Chart-> Insert shape->Select Shape->Shape Styles->Shape Fill->Picture.

    I suggest you make a test with other computers.

    Best Regards,

    Edward


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Friday, October 14, 2016 2:59 AM