Brian C
Brian C

Reputation: 1

Export selected PPT slides as a PDF attachment in outlook email

See code below does work as a PPTX currently.

I need to have this export as a PDF not a PPTX and am having no luck. Help much appreciated! Also having no luck adding an email signature automatically to this code. Granted many users will end up using this macro.


Sub EmailFinal()

 Dim objActivePresetation As Presentation
    Dim objSlide As Slide
    Dim n As Long
    Dim strName As String
    Dim strTempPresetation As String
    Dim objTempPresetation As Presentation
    Dim objOutlookApp As Object
    Dim objMail As Object
 
    Set objActivePresetation = ActivePresentation
 
    For Each objSlide In objActivePresetation.Slides
        objSlide.Tags.Delete ("Selected")
    Next
 
    'Add a tag "Selected" to the selected slides
    For n = 1 To ActiveWindow.Selection.SlideRange.Count
        ActiveWindow.Selection.SlideRange(n).Tags.Add "Selected", "YES"
    Next n
 
    strName = objActivePresetation.Name
    strName = Left(strName, InStrRev(strName, ".") - 1)
    strTempPresetation = Environ("TEMP") & "\" & strName & ".pptx"
 
    'Copy the active presentation to a temp presentation
    objActivePresetation.SaveCopyAs strTempPresetation
    Set objTempPresetation = Presentations.Open(strTempPresetation)
 
    'Remove the untagged slides
    For n = objTempPresetation.Slides.Count To 1 Step -1
        If objTempPresetation.Slides(n).Tags("Selected") <> "YES" Then
           objTempPresetation.Slides(n).Delete
        End If
    Next n
 
    objTempPresetation.Save
    objTempPresetation.Close
 
    'Attach the temp presentation to a new email
    Set objOutlookApp = CreateObject("Outlook.Application")
    Set objMail = objOutlookApp.CreateItem(olMailItem)
 
    'Change the email details as per your needs
    With objMail
         .To = "insertemailhere"
         .Subject = strName
         .Body = "Dear Company," & vbCr & vbCr & "Please see attached Plaques.," & vbCr & "Please let me know if you need any further assistance."
         .Attachments.Add strTempPresetation
         .Display
    End With
End Sub

Thank You!!

Upvotes: 0

Views: 378

Answers (1)

Pᴇʜ
Pᴇʜ

Reputation: 57683

Use the Presentation.ExportAsFixedFormat method.

Instead of objTempPresetation.Save do objTempPresetation.ExportAsFixedFormat and specify your desired parameters but at least specify those parameters:

objTempPresetation.ExportAsFixedFormat Path:="C:\yourpath\yourfile.pdf", FixedFormatType:=ppFixedFormatTypePDF

other parameters are optional.

Upvotes: 1

Related Questions