1

Sorry if title is confusing. I'm trying to execute a multi-app sub that will ultimately e-mail a PDF attachment. The process first starts by extracting information from a CSV, which I've done, then it uses that information to populate a pre-existing slide in PowerPoint, which is also done. The next step is what I can't figure out. There is the ability to create Handouts via PowerPoint, but all I know is how to setup the dialog, and not how to complete the process.

PowerPointApp.CommandBars.ExecuteMso ("CreateHandoutsInWord") will open the dialog, but that's it. I've successfully used SendKeys to execute the rest, but then there is always a failure at the handoff to Word. Putting Waits in the code doesn't help. I'm working on an alternative method now, but was curious if anyone knew how to finish this process.

  Sub CreateHandoutsForWord()

    Dim mailSht As Worksheet
    Dim PowerPointApp As Object
    Dim myPresentation As Object
    Dim sl As Object
    Dim myShape As Object

    Dim impStr As String
    Dim implStr() As String
    Dim wordPath As String

    Dim fso As New FileSystemObject
    Dim fo As Folder
    Dim f As File

    Dim wordApp As New Word.Application
    Dim wordDoc As Word.Document

    Set mailSht = Worksheets("Mailer")

    impStr = OpenCSV
    implStr() = Split(impStr, " ")

    Set fo = fso.GetFolder(mailSht.Range("E5").Value)

    Set f = fo.Files("Mailer.pptx")

    On Error Resume Next

      Set PowerPointApp = GetObject(Class:="PowerPoint.Application")

      Err.Clear

      If PowerPointApp Is Nothing Then Set PowerPointApp = CreateObject(Class:="PowerPoint.Application")

      If Err.Number = 429 Then
        MsgBox "PowerPoint could not be found, aborting."
        Exit Sub
      End If

  On Error GoTo 0


     Application.ScreenUpdating = False

    'Create a New Presentation

    Set myPresentation = PowerPointApp.Presentations.Open(f.Path)

    Set sl = myPresentation.Slides(1)
    sl.Shapes.Range(Array(2, 1)).Item(1).TextFrame.TextRange.Text = "Scott Corwin"
    sl.Shapes.Range(Array(3, 1)).Item(1).TextFrame.TextRange.Text = "Guest Speaker"

    PowerPointApp.CommandBars.ExecuteMso ("CreateHandoutsInWord")

    Application.Wait Now + 0.00003
    PowerPointApp.Activate
    SendKeys "{DOWN}", True

    Application.Wait Now + 0.00001
    PowerPointApp.Activate
    SendKeys "{DOWN}", True

     Application.Wait Now + 0.00001
     PowerPointApp.Activate
     SendKeys "~", True

     Application.Wait Now + 0.0003
     PowerPointApp.Activate
     myPresentation.Close
     PowerPointApp.Quit

     Application.Wait Now + 0.0006
      Set wordApp = GetObject(Class:="Word.Application")

It just ends in a stalled app at this point by giving me a repeated error saying application is not available. Once I figure this out I already have the working code that will create the PDF and e-mail it via Outlook.

3
  • Rather than sendkeys, did you look into PPT VBA. Maybe something like this function: docs.microsoft.com/en-us/office/vba/api/…
    – Tanya
    Commented Mar 10, 2020 at 3:23
  • Hi, yes I did. Unfortunately, that function only seems to export as either a PDF or XPS format. Commented Mar 10, 2020 at 13:26
  • 1
    What about a workaround of exporting all the slides as images and then inserting those into your Word doc, and adding code to create handout lines/layout that you want? free-power-point-templates.com/articles/…
    – Tanya
    Commented Mar 12, 2020 at 3:36

0

You must log in to answer this question.