Excel VBA crashing when referencing a PowerPoint slide index number - excel

A couple of years ago I posted a question about an issue I was having with Excel and Powerpoint VBA on Mac OS X. I never managed to solve the problem, and instead worked around it by installing bootcamp and running it on Windows 10. However, I now have exactly the same problem again, I'd rather not use Windows, and the issue doesn't seem to have resolved itself through updates (I'm now using 365, having started with Office 2016) so I'm back here asking for help.
I have some VBA code that starts a Powerpoint session from Excel and manipulates PowerPoint using content from the Excel workbook. The problem comes whenever I try to reference a specific slide. No matter how I do it, Excel crashes. The crash always occurs at the point of making the reference to the slide index. Here's some simplified code that will trigger the crash:
Sub test()
Dim myApp As PowerPoint.Application
Dim myPres As PowerPoint.Presentation
Dim mySlide As PowerPoint.Slide
Set myApp = CreateObject("PowerPoint.Application")
Set myPres = myApp.Presentations.Add
Set mySlide = myPres.Slides.Add(Index:=1, Layout:=ppLayoutTitleOnly)
Set mySlide = myPres.Slides.Add(Index:=2, Layout:=ppLayoutTitleOnly)
Set mySlide = myPres.Slides(1)
End Sub
That last line before the end sub will cause the crash. This doesn't happen running on Windows. What on earth is going on?
It's incredibly frustrating. I've wasted tons of time trying to fix this, or work around it. I've seen one or two people asking similar questions elsewhere, but never seen a solution to it.
Grateful for any assistance
Thanks

Related

Excel crashes when creating/generating a powerpoint on Mac

I am trying to generate a Powerpoint from Excel with VBA. On Windows everything is working fine. I have very very simple code atm:
Sub pptTest()
Dim PowPntApp As PowerPoint.Application
Dim PowPntPrsnt As PowerPoint.Presentation
Dim PowPntSlide As PowerPoint.Slide
Set PowPntApp = New PowerPoint.Application
PowPntApp.Visible = True
PowPntApp.Activate
Set PowPntPrsnt = PowPntApp.Presentations.Add
Set PowPntSlide = _
PowPntPrsnt.Slides.Add(1, ppLayoutTitle)
End Sub
When I run this macro on my Macbook, it does open powerpoint with a new slide, but it completely crashes Excel to the point I have to force quit the application. Why is that?
Excel version: 16.61.1 (22052000)
Macbook: MacBook Pro (16-inch, 2021) M1 Chip (no clue if this is relevant)
EDIT
I've ran the code a couple of times. Sometimes it works, sometimes it only crashes Excel, sometimes it only crashes Powerpoint and sometimes it crashes both Excel AND Powerpoint. Very inconsistent. Any thoughts?

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:
Open a new presentation from a given template (.potx) in a given path
Add various charts and tables
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.
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.

Trying to build a macro to copy textboxes from Powerpoint to Ex

Attempted to use early binding to assign a powerpoint presentation to a variable so i can call it again to dig deeper into the slides and then shapes to copy textboxes into Excel
but pptApp.Presentations.Open("Presentation1.pptx") keeps getting highlighted for "compile error: Invalid or unqualified reference"
Sub test()
Dim pptApp As Application
Set pptApp = New PowerPoint.Application
pptApp.Visible = True
pptApp .Presentations.Open("Presentation1.pptx")
End Sub
I am familiar with working my way around Excel's object library but powerpoint is still quite new to me and I can't find much information online regarding copying items from powerpoint into excel as usually its done the other way round, would appreciate any additional advice on the useful codes in Powerpoint object library (this is a personal project to automate a mundane task at work)

Slide Selection in PPT on Mac OS

I am trying to create a VBA program to take screen shots from excel to paste them in a PPT template. I have been able to have success with Windows, but I am struggling to get this to work on MAC. I know that there are issues getting Office family products to talk to each other on Office for Mac, but I'm hoping that some of the older problems have been fixed. The questions about this topic, for the most part, are a few years old.
I am able to use the code below to open a ppt template from a directory, but as soon as I try to select a specific slide, it crashes excel. This is the most comprehensive dialog about this topic, but its from around 3 years ago. https://answers.microsoft.com/en-us/msoffice/forum/all/vba-copy-from-mac-excel-2016-and-paste-to/7d177c40-501b-471f-b4b4-81735652d492
Am I missing something stupid? Is there a workaround? Half of my organization uses PC and half Mac, so just using Windows isn't the solution.
Sub CreateDealReviewPPT()
'Declare PPT Variables
Dim PPTApp As PowerPoint.Application
Dim PPTPres As PowerPoint.Presentation
Dim PPTSlide As PowerPoint.Slide
Dim PPTShape As PowerPoint.Shape
'Ranges for the directories
PPTTemplate = Sheets("Start Here - ISSP Instructions").Range("PPTTemplate").Value
Set PPTApp = CreateObject("PowerPoint.Application")
Set PPTPres = PPTApp.Presentations.Open(PPTTemplate)
PPTApp.Visible = True
PPTApp.Activate
PPTSlide = PPTPres.Slides(5)
PPTSlide.Select
When I get to the PPTSlide = PPTPres.Slides(5) it crashes.
I am on Mac OS Catalina. I am using Excel and PPT versions 16.37 on office365.
Office for Mac has a long-standing known bug with CreateObject. It just doesn't work.
In addition, the OLE implementation in Office for Mac is limited in PowerPoint. You can call Excel and Word objects from PowerPoint, but you can't call PowerPoint from either Word or Excel.
On top of that, the post-2011 PowerPoint VBA object model is full of holes: commands and parameters that work fine in Windows fail on the Mac. Sorry, but it's a mess.

powerpoint breaking links via excel vba

I am trying to update a PowerPoint Presentation with embedded charts via Excel by using a VBA script. This works fine with my code. The Problem is that I also want - after the charts have been updated - to break/remove the links to the Excle worksheet.
The code example shows my code also with the line that doesn´t work.
Any suggestion or solution would be highly appreciated!
Function RefreshPPT()
Set PPT = CreateObject("PowerPoint.Application")
PPT.Visible = True
PPT.Presentations.Open "Name.pptx", Untitled:=msoTrue
PPT.ActivePresentation.UpdateLinks
PPT.ActivePresentation.BreakLinks ------ this line doesn´t work
PPT.ActivePresentation.SaveAs Filename:="Name2.pptx"
PPT.Quit
Set PPT = Nothing
End Function
thanks for the answers.
I think I have solved the problem: The syntax of the breakline command was wrong.
I had to address the slides and shapes directly:
PPT.ActivePresentation.Slides(i).Shapes(s).LinkFormat.BreakLink

Resources