Guys,

I have a code that will automatically make a powerpoint presentation from several charts in my excel file. I get a runtime error when running the code on a few of the lines where the charts are copied. I hit debug, go to the actual chart in excel click on it, then go back to code and run and it works till the next time the Copy code comes up. So now I have to hit debug like 5 times then physically click the Chart the code errors out on, then continue running the code. If I immediately run the code again after I have went through and clicked the errored out charts, it works perfectly. IE once I have clicked them once I can run the code again and again without the error. Once I close the workbook and reopen does the Runtime error reoccur.


I figure it is a syntax error but not sure why clicking on the chart makes it work???
Any help is greatly appreciated.

Here is the specific code it errors out on
ActiveWorkbook.Worksheets("MTN_Charts").ChartObjects("MTN").Copy
Here is the entire code
Sub ChartToPresentation()
    'Automatically create powerpoint presentation using Template and pasting in trend graphs
    'Declare variable and type
    Dim PPApp  As PowerPoint.Application
    Dim PPPres As PowerPoint.Presentation
    Dim PPSlide As PowerPoint.Slide
    Dim oPPshape As Object
    Dim Sld As PowerPoint.Slide
    Dim cht As PowerPoint.Chart
    Dim kpitype, SaveDatestrg As String
    Dim SaveDate As Date
    Dim fileNameString As String
    
    'Define values
    fileNameString = "X:\Gordonsville\Production Meetings\Daily GM Visuals\GMVisuals " & Format$(Date, "mm-dd-yyyy")
    kpitype = Range("B5").Value

        ' Open PowerPoint
        Set PPApp = CreateObject("Powerpoint.Application")
        ' Open specific template
        Set PPPres = PPApp.Presentations.Open("X:\Gordonsville\Production Meetings\GmVisualsTemplate.potx")
        
        'Set subtitle dependent on Kpi selected
        PPPres.Slides(1).Shapes(2).TextFrame.TextRange.Text = kpitype
    
    
    ' Begin copy and paste of Charts to specific slides
        ActiveWorkbook.Worksheets("MTN_Charts").ChartObjects("MTN").Copy
        With PPPres.Slides(2).Shapes.Paste
            ' Resize and Align pasted chart
            .Width = 697.122
            .Height = 419.42
            .Align msoAlignCenters, True
            .Align msoAlignMiddles, True
            '.Line.ForeColor.RGB = RGB(192, 80, 77)
                        
        End With
        
        ActiveWorkbook.Worksheets("MTN_Charts").ChartObjects("Cumberland").Copy
        With PPPres.Slides(3).Shapes.Paste
            ' Align pasted chart
            .Width = 697.122
            .Height = 428.42
            .Align msoAlignCenters, True
            .Align msoAlignMiddles, True
           '.Line.ForeColor.RGB = RGB(192, 80, 77)
           End With
           
       
        ActiveWorkbook.Worksheets("MTN_Charts").ChartObjects("Gorwood").Copy
        With PPPres.Slides(4).Shapes.Paste
            ' Align pasted chart
            .Width = 697.122
            .Height = 428.42
            .Align msoAlignCenters, True
            .Align msoAlignMiddles, True
        End With
            
            'Skip elmwood if ore hoisted
                 If kpitype = "Ore Hoisted" Then
                    With PPPres.Slides(5)
                        Set oPPshape = .Shapes.AddTextbox(Orientation:=msoTextOrientationHorizontal, Left:=100, Top:=50, Width:=400, Height:=100)
                        oPPshape.TextFrame.TextRange.Text = "Hoisting not available at Elmwood!" & vbNewLine & "All ore produced at elmwood is transported and hoisted in Gordonsville"
                    End With
                 GoTo Skip
                 Else
                 
            ActiveWorkbook.Worksheets("MTN_Charts").ChartObjects("Elmwood").Copy
        With PPPres.Slides(5).Shapes.Paste
            ' Align pasted chart
            .Width = 697.122
            .Height = 428.42
            .Align msoAlignCenters, True
            .Align msoAlignMiddles, True
        End With
            End If
Skip:

        ActiveWorkbook.Worksheets("ETN_Charts").ChartObjects("ETN").Copy
        With PPPres.Slides(6).Shapes.Paste
            ' Align pasted chart
            .Width = 697.122
            .Height = 428.42
            .Align msoAlignCenters, True
            .Align msoAlignMiddles, True
        End With
        
        ActiveWorkbook.Worksheets("ETN_Charts").ChartObjects("Coy").Copy
        With PPPres.Slides(7).Shapes.Paste
            ' Align pasted chart
            .Width = 697.122
            .Height = 428.42
            .Align msoAlignCenters, True
            .Align msoAlignMiddles, True
        End With
        
        ActiveWorkbook.Worksheets("ETN_Charts").ChartObjects("Immel").Copy
        With PPPres.Slides(8).Shapes.Paste
            ' Align pasted chart
            .Width = 697.122
            .Height = 428.42
            .Align msoAlignCenters, True
            .Align msoAlignMiddles, True
        End With
        
        ActiveWorkbook.Worksheets("ETN_Charts").ChartObjects("Young").Copy
        With PPPres.Slides(9).Shapes.Paste
            ' Align pasted chart
            .Width = 697.122
            .Height = 428.42
            .Align msoAlignCenters, True
            .Align msoAlignMiddles, True
        End With
        'Savefile
        PPPres.SaveAs fileNameString, 1
        
        ' Clean up
        Set PPSlide = Nothing
        Set PPPres = Nothing
        Set PPApp = Nothing
        
End Sub