Create a Word document based on a PowerPoint presentation

Sometimes it can be handy to have a more detailed document with information that belongs to the slideshow displayed on the projector. This document can have e.g. code samples, diagrams and other relevant information that doesn’t fit on the PowerPoint presentation. I needed to do this when writing course material, so I created this script that creates a Word document with the slide as a miniature image so that it is possible to add comments or key points.

This script creates a linked PowerPoint slide object in a Word document. The script also extracts the notes belonging to the slide and adds them to the current page. Each slide in the presentation will generate one page in the Word document and the linked PowerPoint slide will be centered and resized to 9 centimeters.

In order to make this script work, simply just paste this code into the macro editor in your word document.

Sub CreateWordPagesBasedOnPowerPointPresentationLink()

    Dim sImagePath As String
    Dim sImageName As String
    Dim objPPT As PowerPoint.Application
    
    Dim oSlide As Slide '* Slide Object
    On Error GoTo Err_ImageSave
    
    strDocPath = InputBox("Path: ", _
        "Path to PowerPoint presentation", _
        "C:\MyPath\MyPresentation.pptx")
    
    Set objPPT = CreateObject("Powerpoint.application")
    'objPPT.Visible = False
    objPPT.Presentations.Open strDocPath
    
    For Each oSlide In objPPT.ActivePresentation.Slides
        If Not oSlide.SlideShowTransition.Hidden = msoTrue Then
            sImageName = oSlide.Name & ".PNG"
        
            oSlide.Copy
    
            Selection.PasteSpecial Link:=True, DataType:=wdPasteOLEObject, Placement:= _
                wdInLine, DisplayAsIcon:=False

            Selection.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
            With Selection.Borders(wdBorderTop)
                .LineStyle = Options.DefaultBorderLineStyle
                .LineWidth = Options.DefaultBorderLineWidth
                .Color = Options.DefaultBorderColor
            End With
            With Selection.Borders(wdBorderLeft)
                .LineStyle = Options.DefaultBorderLineStyle
                .LineWidth = Options.DefaultBorderLineWidth
                .Color = Options.DefaultBorderColor
            End With
            With Selection.Borders(wdBorderBottom)
                .LineStyle = Options.DefaultBorderLineStyle
                .LineWidth = Options.DefaultBorderLineWidth
                .Color = Options.DefaultBorderColor
            End With
            With Selection.Borders(wdBorderRight)
                .LineStyle = Options.DefaultBorderLineStyle
                .LineWidth = Options.DefaultBorderLineWidth
                .Color = Options.DefaultBorderColor
            End With
            
            Selection.MoveRight Unit:=wdCharacter, Count:=1
            Selection.TypeParagraph
            Selection.TypeParagraph
            
            If oSlide.NotesPage.Shapes.Placeholders.Count > 0 Then
            Dim foo As Object
                Selection.TypeText (oSlide.NotesPage.Shapes.Placeholders(2).TextFrame.TextRange.Text)
                Selection.TypeParagraph
            End If
            Selection.InsertBreak Type:=wdPageBreak
        End If
        DoEvents
    Next oSlide
    
    objPPT.Quit
    Set objPPT = Nothing
    
    For Each oShape In ActiveDocument.InlineShapes
        With oShape
            .LockAspectRatio = msoTrue
            .Width = CentimetersToPoints(8.99)
            .Height = CentimetersToPoints(6.74)
            .Range.ParagraphFormat.Alignment = wdAlignParagraphCenter
        End With
    Next oShape

Err_ImageSave:
        If Err <> 0 Then
            MsgBox Err.Description
        End If

End Sub
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s