Search code examples
excelvbapowerpoint

Excel hard crashes when I try to modify a PowerPoint presentation through macro


Helo all, I'm trying to automate the reporting system at my work. To this end I'm setting up a Macro that, at the press of a button in Excel, will:

  1. Open a new presentation from a given template (.potx) in a given path
  2. Add various charts and tables
  3. Save the newly created presentation in another given path

As this is pretty new to me I'm moving step by step, but I'm stuck at the beginning. This is my code so far:


    Dim PP As PowerPoint.Application
    Dim report As PowerPoint.Presentation
    Dim report_activeslide As PowerPoint.Slide
    'Dim Slide_1_text As Shape
    Dim path_template As String
    Dim path_report As String
    
    path_template = "path_template.potx"
    path_report = "path_report"
    
    Set PP = New PowerPoint.Application
    Set report = PP.Presentations.Open(path_template, False, True, True)
    
    PP.Visible = msoTrue
    
    'Set report_activeslide = report.Slides(1)
    
    report.SaveAs path_report, ppSaveAsOpenXMLPresentation, msoTrue
    
End Sub

As of now I'm able to open the presentation from the template and correctly save it. However, the moment I actually start doing anything on the presentation itself, for example taking the comment off the 'Set report_activeslide = report.Slides(1) line, Excel hard crashes.

Does anyone know where the problem is? I'm running Office 365 on Mac if that may be of any difference.


Solution

  • As Ike in the comments pointed out, the code works on Windows (I had the chance to test it myself). This pointed me to the possibility of my problem being due to Mac, not to code and, as it turns out, this is correct. Indeed there are more than a few people reporting the same issue (see for example: Excel VBA crashing when referencing a PowerPoint slide index number)

    So for now, until Microsoft provides a better implementation of OLE there is nothing I can realistically do to solve this.