0

I am experiencing an odd behavior of my PowerPoint Ribbon.

I created a pptm file with a Ribbon for a quick-link to 2 vba codes. One is copying data from an xls-file to a chart. The other one is saving a copy of the presentation as a pptx file and a pdf file (savecopyas) and sends an email with outlook.

Everything works smooth as long as I only save the pdf file. If I also create the pptx file (or a different named pptm file) the vba script only runs the first time - afterwards the ribbon for both actions ist not working anymore. It is prompting an error saying the vba code was not found.

What did I experience?

1) The xls-code runs as often as you like as long as the email code is not started.

2) There is no warning that the pptx file will not contain any vba code anymore (that's what Excel would tell you)

3) If I add a last line that is saving the pptm as pptx, the modules keep in the pptx until it is closed. The ribbon commands are working correctly in this case of a pptx file - as often as you like.

4) Starting the email vba code in the pptm from a button manually works smooth all the time, no matter how often it is started.

I only found 2-3 similar questions / errors on the web with no explanation or only workarounds.

Is there anybody who can explain and help me on this odd behavior?

Kind regards,

Mario

Here is the code:

Sub Email(ByVal control As IRibbonControl)

Dim Send_Email, olApp As Object
Dim Send_1, Send_2 As String

With ActivePresentation
.SaveCopyAs _
    FileName:=ActivePresentation.Path & "\" & "Test" & ".pptx", _
    FileFormat:=ppSaveAsOpenXMLPresentation
End With

With ActivePresentation
.SaveCopyAs _
    FileName:=ActivePresentation.Path & "\" & "Test" & ".pdf", _
    FileFormat:=ppSaveAsPDF
End With

Send_1 = ActivePresentation.Path & "\" & "Test" & ".pptx"
Send_2 = ActivePresentation.Path & "\" & "Test" & ".pdf"

Set olApp = CreateObject("Outlook.Application")

Set Send_Email = olApp.CreateItem(0)

With Send_Email
 .To = "test@gmail.com"
 .Subject = "Test"
 .Body = "Hallo "
 .Attachments.Add Send_2
 .Attachments.Add Send_1
 .Send
End With

Set olApp = Nothing

End Sub

1 Answers1

0

If you want the VBA macro working you need to save presentation in the .pptm (macro enabled) format. By default, pptx doesn't have/run the VBA code.

Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45
  • What @Eugene said. And since you're saving the PPTX via code rather than user activity, it doesn't ask you whether you want to save as PPTM or lose the code, it just does what you tell it to do. You're the programmer; you're expected to KNOW that saving as PPTX will remove the code. – Steve Rindsberg Dec 05 '14 at 16:32
  • @Steve, Sorry for being imprecise, I want a copy of the active presentation without the macros. Therefore I am using SaveCopyAs. The active presentation keeps the original pptm file with the macro. The question is: Why ist the ribbon not working anymore? The SaveAs pptx was just an attempt - an what puzzles me is that the ribbon then keeps working. – Mario Hofer Dec 05 '14 at 22:38
  • "Why ist the ribbon not working anymore? The SaveAs pptx was just an attempt - an what puzzles me is that the ribbon then keeps working" This confuses me, @Mario. The ribbon's not working any more but the ribbon keeps working? ;-) But I may've seen something like this: you save a presentation with macros as a PPTX but the macros continue to function; in this case, because what's in memory is the original PPTM, even though PPT now calls it a PPTX. The macros will cease working when you close then reopen the PPTX, though. – Steve Rindsberg Dec 06 '14 at 17:49
  • By the way, you may be far better off distributing your code as an add-in (PPAM). – Steve Rindsberg Dec 06 '14 at 17:49
  • @Steve If I use the code above the ribbon will work the first time. The email is send and I have PPT open with the original, unchanged pptm file. However, if I click on the ribbon icon again, I get an error message and can start the macro only manually. If I add a last line with a saveas function and get a pptx file open after starting the macro with the ribbon then I can use the ribbon and start the macro over and over again - and this is illogical to me. – Mario Hofer Dec 06 '14 at 23:22