• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Method 'item'of the object 'shapes'failed'

Balajisx

Member
Hi All,

I am working on automation where I am exporting the charts from excel to powerpoint.
When I run the code by step by step it is working perfectly. However when I run the sub command I am getting the runtime error stating 'Method 'item'of the object 'shapes'failed'. I tried with couple of ways however I am not able to fix the issue. I have grouped all the charts and objects and named it as 1 ,2,3 etc. I need to keep the source and formatting hence I preferred

ppapp.CommandBars.ExecuteMso ("PasteSourceFormatting")


I am not sure what is causing the issue. Please assist.

code below

Code:
Sub senttoppt()

Dim wb As Workbook
Set wb = ActiveWorkbook
Dim ppapp As PowerPoint.Application
Dim ppres As PowerPoint.Presentation

Set ppapp = New PowerPoint.Application
ppapp.Visible = msoTrue

ActiveWorkbook.Sheets("Dashboard").Visible = True

    ActiveWorkbook.Sheets("Dashboard").Select
  
    Set ppres = ppapp.Presentations.Open(Application.GetOpenFilename(), , msoFalse)
  
    Set ppres = ppapp.ActivePresentation
    Dim shapes As Object

Dim pslide As PowerPoint.Slide
  
Set pslide = ppres.Slides.Add(2, ppLayoutBlank)

ActiveSheet.shapes.Range(Array("1")).Select
Selection.Copy
ppres.Slides(2).shapes.PasteSpecial (ppPasteShape)
pslide.shapes("1").Width = ppres.PageSetup.SlideWidth
pslide.shapes("1").Top = 10
pslide.shapes("1").Left = 0

Set pslide = ppres.Slides.Add(3, ppLayoutBlank)
ActiveSheet.shapes.Range(Array("2")).Select
Selection.Copy
ppres.Slides(3).shapes.PasteSpecial (ppPasteShape)
pslide.shapes("2").Width = ppres.PageSetup.SlideWidth
pslide.shapes("2").Top = 10
pslide.shapes("2").Left = 0

Set pslide = ppres.Slides.Add(4, ppLayoutBlank)
ActiveSheet.shapes.Range(Array("3")).Select
Selection.Copy
ppres.Slides(4).shapes.PasteSpecial (ppPasteShape)
pslide.shapes("3").Width = ppres.PageSetup.SlideWidth
pslide.shapes("3").Top = 10
pslide.shapes("3").Left = 0


Set pslide = ppres.Slides.Add(5, ppLayoutBlank)
ActiveSheet.shapes.Range(Array("4")).Select
Selection.Copy
ppres.Slides(5).Select
ppapp.CommandBars.ExecuteMso ("PasteSourceFormatting")
Application.Wait (Now + TimeValue("00:00:02"))
pslide.shapes("4").Width = ppres.PageSetup.SlideWidth
pslide.shapes("4").Top = 10
pslide.shapes("4").Left = -5

Set pslide = ppres.Slides.Add(6, ppLayoutBlank)
ActiveSheet.shapes.Range(Array("5")).Select
Selection.Copy
ppres.Slides(6).shapes.PasteSpecial (ppPasteShape)
pslide.shapes("5").Width = ppres.PageSetup.SlideWidth
pslide.shapes("5").Top = 10
pslide.shapes("5").Left = 0

Set pslide = ppres.Slides.Add(7, ppLayoutBlank)
ActiveSheet.shapes.Range(Array("6")).Select
Selection.Copy
ppres.Slides(7).shapes.PasteSpecial (ppPasteShape)
pslide.shapes("6").Width = ppres.PageSetup.SlideWidth
pslide.shapes("6").Top = 10
pslide.shapes("6").Left = 0

Set pslide = ppres.Slides.Add(8, ppLayoutBlank)
ActiveSheet.shapes.Range(Array("7")).Select
Selection.Copy
ppres.Slides(8).shapes.PasteSpecial (ppPasteShape)
pslide.shapes("7").Width = ppres.PageSetup.SlideWidth
pslide.shapes("7").Top = 10
pslide.shapes("7").Left = 0


Set pslide = ppres.Slides.Add(9, ppLayoutBlank)
ActiveSheet.shapes.Range(Array("8")).Select
Selection.Copy
ppres.Slides(9).Select
ppapp.CommandBars.ExecuteMso ("PasteSourceFormatting")
pslide.shapes("8").Width = ppres.PageSetup.SlideWidth
pslide.shapes("8").Top = 10
pslide.shapes("8").Left = 0

End Sub
 
Hi, Balajisx!
Consider uploading a sample file. It'd be easier to understand for people who might be able to help you. Thanks.
Regards!
 
The requirement is to keep the charts and groups in the same format what I have in excel. when I tried using ppapp.CommandBars.ExecuteMso ("PasteSourceFormatting") command, I am getting this run time error. If I change the pasting type as Bitmap or JPEG when ever I run the code the picture name is changing as defalut name hence I am not able to refer the picture to allign them on top and left.

Please help me in pasting them in the same format and allign them on top and left.

Your help is much appreciated
 
Back
Top