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