Using same workbook and applying two different methods:
• Using macro in the xlsm file - works OUTCOME: copies all table ranges and chart objects into separate PPT objects as expected
• Using macro through add - in button - fails | OUTCOME: creates an empty PPT slide, and finishes the macro
Sub ExcelChartsToPPt()
Dim PowerPointApp As Object
Dim myPresentation As Object
Dim mySlide As Object
Dim myShape As Object
Dim oChrt As ChartObject
'Dim for loops
Dim i As Integer
Dim j As Integer
If PowerPointApp Is Nothing Then _
Set PowerPointApp = CreateObject(class:="PowerPoint.Application")
On Error GoTo 0
Application.ScreenUpdating = False
Set myPresentation = PowerPointApp.Presentations.Add
'Count number of worksheets and loop that many times
For i = 1 To ThisWorkbook.Worksheets.Count
For j = 1 To Worksheets(i).ChartObjects.Count
Set oChrt = ActiveSheet.ChartObjects(j)
Set mySlide = myPresentation.Slides.Add(1, 11) '11 = ppLayoutTitleOnly
'copy chart objects from worksheets
Worksheets(i).ChartObjects(j).Copy
Set rngoChrt = Range(oChrt.TopLeftCell, oChrt.BottomRightCell)
With rngoChrt
'Range of data cells in relation to the chart
Set rngData = .Offset(4, .Columns.Count).Cells(1).Resize(10, 3)
rngData.Copy
End With
mySlide.Shapes.Paste
Set myShape = mySlide.Shapes(mySlide.Shapes.Count)
myShape.Left = 200
myShape.Top = 200
PowerPointApp.Visible = True
PowerPointApp.Activate
Application.CutCopyMode = False
Next j
Next i
End Sub
Bookmarks