Nils
Nils

Reputation: 930

Turning Display Alerts off in PowerPoint from Excel

I am writing a macro that opens and closes a PowerPoint Presentation from Excel. Now I have the issue that when I am trying to save the PowerPoint file I get a pop up Message Box. To take care of that issue I used:

Application.DisplayAlerts = False

However this works in some cases, as I loop through multiple Presentations but not in all. So I tried instead this:

pptPres.Application.DisplayAlerts = False

But this just caused the Display Alerts to always pop up.

So I tried to replicate that using

Application.DisplayAlerts = True

which did not work. So I am quite confused what I am doing wrong. I need to turn the DisplayAlerts off otherwise my macro is stopped.

The issue occurs as I am opening a PowerPoint with macros so a *.pptm file which on saving I am asked whether or not to save with macros.

This is my current code, maybe you can replicate the issue:

Dim pptPres As PowerPoint.Presentation

Set pptApp = CreateObject("powerpoint.Application")

Set pptPres = pptApp.Presentations.Open(strPfad & strDat, False, True, True)

pptPres.Application.DisplayAlerts = False


strFirma = "Test123"
pptPres.SaveAs strPfad + "\Berichte" & "\" & strFirma & ".pptx"
pptPres.Close

Any help is greatly appreciated.

Upvotes: 3

Views: 965

Answers (1)

BigBen
BigBen

Reputation: 49998

Powerpoint's Application.DisplayAlerts is slightly different. It has two options: ppAlertsAll and ppAlertsNone.

Try pptApp.DisplayAlerts = ppAlertsNone. Note that you have a mix of early- and late-binding and probably should be consistent. If you go with late-binding, ppAlertsAll's corresponding value is 2, and ppAlertsNone's corresponding value is 1.

Thanks to @Matthieu Guindon for pointing out that since you're running this from Excel, Application refers to Excel.Application, which is not your instance of PowerPoint. Hence Application.DisplayAlerts will not affect PowerPoint's alert setting at all. You want to work with pptApp, the instance of PowerPoint.

Upvotes: 4

Related Questions