+ Reply to Thread
Results 1 to 10 of 10

Attaching PDFs from PowerPoint and Email

Hybrid View

  1. #1
    Registered User
    Join Date
    05-14-2013
    Location
    Ontario, Canada
    MS-Off Ver
    Excel 2007
    Posts
    92

    Attaching PDFs from PowerPoint and Email

    Im using this code, but not sure where to add in code to attach to an email and display. Anyone can help?

    Sub ExportSlidesToIndividualPDF()
    Dim oPPT As Presentation, oSlide As Slide
    Dim sPath As String, sExt As String

    Set oPPT = ActivePresentation
    sPath = oPPT.FullName & "_Slide_"
    sExt = ".pdf"

    For Each oSlide In oPPT.Slides
    i = oSlide.SlideNumber
    oSlide.Select
    oPPT.ExportAsFixedFormat _
    Path:=sPath & i & sExt, _
    FixedFormatType:=ppFixedFormatTypePDF, _
    RangeType:=ppPrintSelection
    Next
    Set oPPT = Nothing
    End Sub

  2. #2
    Registered User
    Join Date
    05-14-2013
    Location
    Ontario, Canada
    MS-Off Ver
    Excel 2007
    Posts
    92

    Re: Attaching PDFs from PowerPoint and Email

    Anyone? Any thing?

  3. #3
    Forum Expert daffodil11's Avatar
    Join Date
    07-11-2013
    Location
    Phoenixville, PA
    MS-Off Ver
    MS Office 2016
    Posts
    4,465

    Re: Attaching PDFs from PowerPoint and Email

    Do you want to send them all in a single email, together?

    If so, I'd probably add each name created to a Scripting.Dictionary, and after all were made would then create an outlook mail item and attach each by then referring to the index of name in the dictionary. Is this what you need?
    Make Mom proud: Add to my reputation if I helped out!

    Make the Moderators happy: Mark the Thread as Solved if your question was answered!

  4. #4
    Registered User
    Join Date
    05-14-2013
    Location
    Ontario, Canada
    MS-Off Ver
    Excel 2007
    Posts
    92

    Re: Attaching PDFs from PowerPoint and Email

    After some consideration, I just need to attach the power point to an email, what would be the easiest code for that (not separating into individual PDFs)?

  5. #5
    Forum Expert daffodil11's Avatar
    Join Date
    07-11-2013
    Location
    Phoenixville, PA
    MS-Off Ver
    MS Office 2016
    Posts
    4,465

    Re: Attaching PDFs from PowerPoint and Email

    If you still want to export as a single PDF, this might work for you as well:

    Sub ExportSlidesToIndividualPDF()
    Dim oPPT As Presentation: Set oPPT = ActivePresentation
    Dim sExt As String: sExt = ".pdf"
    Dim olApp As Outlook.Application: Set olApp = New Outlook.Application
    Dim olMail As Outlook.MailItem: Set olMail = olApp.CreateItem(olMailItem)
    
    NewFile = oPPT.FullName & oPPT.Slides.Count & Format(Date, "mm-dd-yyyy") & sExt
    
    oPPT.SaveAs NewFile
    
    With olMail
        .To = "[email protected]"
        .Subject = "Awesome"
        .Attachments.Add NewFile
        .Display
    End With
    
    Set oPPT = Nothing
    Set olMail = Nothing
    Set olApp = Nothing
    End Sub

  6. #6
    Forum Expert daffodil11's Avatar
    Join Date
    07-11-2013
    Location
    Phoenixville, PA
    MS-Off Ver
    MS Office 2016
    Posts
    4,465

    Re: Attaching PDFs from PowerPoint and Email

    Like this?

    Sub ExportSlidesToOutlook()
    Dim oPPT As Presentation
    Set oPPT = ActivePresentation
    
    Dim olApp As Outlook.Application
    Set olApp = New Outlook.Application
    Dim olMail As Outlook.MailItem
    Set olMail = olApp.CreateItem(olMailItem)
    
    With olMail
        .To = "[email protected]"
        .Subject = "Yeah"
        .Attachments.Add oPPT.FullName
        .Display
    End With
    
    Set oPPT = Nothing
    Set olMail = Nothing
    Set olApp = Nothing
    End Sub

  7. #7
    Registered User
    Join Date
    05-14-2013
    Location
    Ontario, Canada
    MS-Off Ver
    Excel 2007
    Posts
    92

    Re: Attaching PDFs from PowerPoint and Email

    Im trying to use the above, but its throwing an error on the Dim olApp As Outlook.Application

  8. #8
    Forum Expert daffodil11's Avatar
    Join Date
    07-11-2013
    Location
    Phoenixville, PA
    MS-Off Ver
    MS Office 2016
    Posts
    4,465

    Re: Attaching PDFs from PowerPoint and Email

    Oh yeah, there we go. I don't know a thing about PowerPoint but I'm pretty handy with franken-coding.

    The hard part is figuring out the names of everything. I worked on my original idea until it finally paid off:

    Sub ExportSlidesToIndividualPDF()
    
    Dim oPPT As Presentation: Set oPPT = ActivePresentation
    Dim sExt As String: sExt = ".pdf"
    Dim oSlide As Slide
    
    'Set reference to MS Outlook 14.0 Library
    Dim olApp As Outlook.Application: Set olApp = New Outlook.Application
    Dim olMail As Outlook.MailItem: Set olMail = olApp.CreateItem(olMailItem)
    
    'Set reference to MS Scripting Runtime
    Dim objDict As Object: Set objDict = CreateObject("Scripting.dictionary")
    
    For i = 1 To oPPT.Slides.Count
        sPath = oPPT.FullName & oPPT.Slides(i).Shapes(1).TextFrame.TextRange.Text
        oPPT.Slides(i).Select
        strSaveName = Replace(sPath, ".ppt", "") & "_Slide_" & Format(i, "000") & sExt
        oPPT.ExportAsFixedFormat _
            Path:=strSaveName, _
            FixedFormatType:=ppFixedFormatTypePDF, _
            RangeType:=ppPrintSelection
        objDict.Add i, strSaveName
    Next
    
    With olMail
        .To = "wow_this@was_hard.com" 'You can also add in .CC if you want
        .Subject = "Awesome"
        With .Attachments
            For c = 0 To objDict.Count
                .Add objDict.Items()(c)
            Next
        End With
        .Display 'Change .Display to .Send to send instantly without prompting you
    End With
    
    Set oPPT = Nothing
    Set olMail = Nothing
    Set olApp = Nothing
    Set objDict = Nothing
    End Sub

    This will save each Slide as a single PDF, with the slide number, and save the name of each to a little invisible floaty index while it goes.
    Then when it creates a new mail item, it goes back to the "scripting dictionary" thingy and pulls all the file names it stored from before and attaches them.

    I just taught myself Scription.Dictionary on Friday, glad to see I already found a use for it.

  9. #9
    Forum Expert daffodil11's Avatar
    Join Date
    07-11-2013
    Location
    Phoenixville, PA
    MS-Off Ver
    MS Office 2016
    Posts
    4,465

    Re: Attaching PDFs from PowerPoint and Email

    For c = 0 To objDict.Count-1

    Maybe

  10. #10
    Forum Expert daffodil11's Avatar
    Join Date
    07-11-2013
    Location
    Phoenixville, PA
    MS-Off Ver
    MS Office 2016
    Posts
    4,465

    Re: Attaching PDFs from PowerPoint and Email

    You have to set the references as indicated by the comments.
    You need to go to Tools->References and check the boxes for Microsoft Outlook and Microsoft Scripting Runtime.

    And I confirmed my suspicions with regards to solving the runtime error, the 'For c = 0 to ...' needs a -1 at the end.

    Sub ExportSlidesToIndividualPDFs()
    
    Dim oPPT As Presentation: Set oPPT = ActivePresentation
    Dim sExt As String: sExt = ".pdf"
    Dim oSlide As Slide
    
    'Set reference to MS Outlook 14.0 Library
    Dim olApp As Outlook.Application: Set olApp = New Outlook.Application
    Dim olMail As Outlook.MailItem: Set olMail = olApp.CreateItem(olMailItem)
    
    'Set reference to MS Scripting Runtime
    Dim objDict As Object: Set objDict = CreateObject("Scripting.dictionary")
    
    For i = 1 To oPPT.Slides.Count
        sPath = oPPT.FullName & oPPT.Slides(i).Shapes(1).TextFrame.TextRange.Text
        oPPT.Slides(i).Select
        strSaveName = Replace(sPath, ".ppt", "") & "_Slide_" & Format(i, "000") & sExt
        oPPT.ExportAsFixedFormat _
            Path:=strSaveName, _
            FixedFormatType:=ppFixedFormatTypePDF, _
            RangeType:=ppPrintSelection
        objDict.Add i, strSaveName
    Next
    
    With olMail
        .To = "wow_this@was_hard.com" 'You can also add in .CC if you want
        .Subject = "Awesome"
        With .Attachments
            For c = 0 To objDict.Count-1
                .Add objDict.Items()(c)
            Next
        End With
        .Display 'Change .Display to .Send to send instantly without prompting you
    End With
    Last edited by daffodil11; 07-21-2015 at 09:12 AM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. export to pdf not attaching to the email
    By dantray02 in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 01-30-2014, 01:23 PM
  2. [SOLVED] Attaching Picture to Email
    By Janie in forum Outlook Formatting & Functions
    Replies: 4
    Last Post: 07-30-2013, 04:23 PM
  3. [SOLVED] Attaching PDFs in a folder to an email.
    By yeahyeahyeah in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-02-2012, 06:02 PM
  4. Attaching files to an email
    By damage in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-12-2011, 01:14 PM
  5. Macro. compiling email, attaching 1x sheet + 1x powerpoint file.
    By rain4u in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-28-2011, 02:24 PM
  6. [SOLVED] Attaching to an email corrupts workbook
    By edger in forum Excel General
    Replies: 1
    Last Post: 02-10-2006, 06:40 PM
  7. Attaching One Worksheet to Email
    By KeshnerH in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-26-2005, 04:06 PM
  8. [SOLVED] attaching tabs to email
    By please help in forum Excel General
    Replies: 3
    Last Post: 01-19-2005, 04:06 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1