Slide Selection in PPT on Mac OS - excel

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.

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.

Excel VBA crashing when referencing a PowerPoint slide index number

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

Unable to open an existing PowerPoint Presentation (2016) from Excel using VBA

I have tried to use a code snippet from a previous question on Stack Overflow just starting with opening an existing PowerPoint file from Excel using VBA. The example code snippet will not work for me.
I am using Excel 2016, and the reference object mode is Microsoft Object Model 16 Library, not the Model 12 referred to earlier. Maybe this is the source of the problem. The procedure I wrote, modified from this site was
Public Sub OpenPPT()
Dim DestinationPPT As String
Dim PowerPointApp As PowerPoint.Application
Dim myPresentation As PowerPoint.Presentation
'Easier to define manually set links up front so it's easier to change/modify
DestinationPPT = "D:\Downloads\Automate_Excel\IR_Seeker_UpdateRevA.pptx"
Set myPresentation = PowerPointApp.Presentations.Open(DestinationPPT)
End Sub
The routine gags on the Set myPresentation line
Try adding this line, so that you open the PowerPoint Application, before you try to open the Presentation in it:
Set PowerPointApp = New PowerPoint.Application
As an analogy: you need to make sure that you are looking at a building before you try to open the door...
You should change
Set myPresentation = PowerPointApp.Presentations.Open(DestinationPPT)
To
Set myPresentation = PowerPointApp.myPresentation.Open(DestinationPPT)
I would also add "Option explicit" outside of all the subs so it will yell at you if you have a undefined variable as well as correct some variable typos.

VBA fails when opening PowerPoint presentation on Windows 7

I wrote a VBA macro in Excel 2007 on Windows XP to copy data from an excel spreadsheet into a powerpoint presentation.
When this macro enabled spreadsheet was run on a fresh install of Windows 7 it fails.
So I pulled out the code that fails to pin point the problem and it seems to fail when trying to open an existing powerpoint file. I have tried running this code in both Office 2010 and Office 2007.
The code I am trying to use it (just the problem parts shown below)
Sub test()
Dim PowerPointApplication As PowerPoint.Application
Dim PowerPointFile As PowerPoint.Presentation
Set PowerPointApplication = CreateObject("PowerPoint.Application")
Set PowerPointFile = PowerPointApplication.Presentations.Open("PATH_TO_FILE\test.pptx")
End Sub
The macro fails on the Presentations.Open line above with the following error
Run-time error '-2147467259 (80004005)':
Method 'Open' of object 'Presentations' failed
I have already enabled the PowerPoint 12.0 Object Library in the references settings in the VBEditor for the spreadsheet. All the other references match exactly with the file that runs without error on my Windows XP box.
I have looked all over the web for an answer and cant find anything. I read something about Windows 7 and offline files, so tried turning that off but it didnt help.
I am logged in as an administrator user as well, and tried moving the pptx that I am opening to other directories as well with no success.
I am running the following version of Windows:
Windows 7 Professional
Service Pack 1
64 Bit
Any help would be appreciated!
Is PATH_TO_FILE a variable (or constant)??
If so shouldn't it be
PowerPointFile = PowerPointApplication.Presentations.Open(PATH_TO_FILE & "\test.pptx")
This does work in office 2016 on Win7 SP1 64bit OS
Should be good for Office 2010.
Could be John's advise on the path to file, also.
Sub test()
Dim PowerPointFile As PowerPoint.Presentation
Dim PPTObj As Object
Set PPTObj = CreateObject("PowerPoint.application")
Set PowerPointFile = PPTObj.Presentations.Open("C:\test.pptx")
End Sub

Resources