Click here to Skip to main content
15,885,757 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Sub Torecognitionplus()

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 = "insert emailhere"
         .Subject = strName
         .Body = "Dear companyX," & 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


What I have tried:

This does work correctly and attaches to email as a PPT File. I need the selected slides in PPT exported as a PDF attachment instead. Can't seem to get it to work.
Posted
Updated 5-Aug-21 5:51am
Comments
CHill60 5-Aug-21 11:34am    
"Can't seem to get it to work." does not help us to help you. What went wrong? Importantly what code did you try? (This code only saves a pptx)
Did you try using saveas"?
ExportAsFixedFormat

I've just used this code snippet to save one of my own .pptx files as a pdf

VB
Dim oPresentation As Presentation
    Set oPresentation = ActivePresentation
    
    Dim targetFolder As String, targetFile As String
    targetFolder = oPresentation.Path
    targetFile = Replace(oPresentation.Name, ".pptx", ".pdf")
    
    oPresentation.ExportAsFixedFormat Path:=targetFolder & "\" & targetFile, FixedFormatType:=ppFixedFormatTypePDF
 
Share this answer
 
Presentation.SaveAs method (PowerPoint) | Microsoft Docs[^]
VB
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

Dim strPdfName As String
strPdfName = Environ("TEMP") & "\" & strName & ".pdf"
objTempPresetation.SaveAs strPdfName, ppSaveAsPDF
objTempPresetation.Close

...

With objMail
   ...
   .Attachments.Add strPdfName
   ...
 
Share this answer
 
Comments
Brian Chiasson 5-Aug-21 12:21pm    
Thanks Richard!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900