Supercharge your PowerPoint productivity with
Supercharge your PPT Productivity with PPTools - Click here to learn more.

PPTools

Image Export converts PowerPoint slides to high-quality images.

PPT2HTML exports HTML even from PowerPoint 2010 and 2013, gives you full control of PowerPoint HTML output, helps meet Section 508 accessibility requirements

Merge Excel data into PowerPoint presentations to create certificates, awards presentations, personalized presentations and more

Resize your presentations quickly and without distortion

Language Selector switches the text in your presentation from one language to another

FixLinks prevents broken links when you distribute PowerPoint presentations

Shape Styles brings styles to PowerPoint. Apply complex formatting with a single click.

Prep4PDF preserves interactivity in PowerPoint presentations when you convert to PDF

Add new slides with titles and text from a text file

Problem

You have a list of titles and text that you want to convert to PowerPoint slides.

Sending the from Word to PowerPoint requires that your Word file be formatted the way PPT expects it, which isn't always what you'd expect.

Importing the text into PowerPoint is simpler but still needs a bit of pre-formatting. Also there's a limit to the number of slides you can import this way, at least in older versions of PowerPoint.

Solution

This VBA macro will import a correctly (but minimally) formatted file into PowerPoint.

The odd-numbered lines from the file become slide titles.
The even numbered line following each title becomes the text underneath the slide title.
The file should look something like this:

Heading1
Text that's to appear under heading 1
Heading2
Text that's to appear under heading 2
Heading3
And so on

Make sure there are no blank lines in the file (unless you want either the title or text to be blank for a particular slide).

Slides will be added to the end of the current presentation.

Sub HeadingsAndTextFromFile()

' Purpose:
' Read a plain text file like this:

'Heading1
'Text that's to appear under heading 1
'Heading2
'Text that's to appear under heading 2
'Heading3
'And so on

' And convert it to a presentation with one slide per Heading in the file

Dim sFileName As String
Dim iFileNum As Integer
Dim sHeading As String
Dim sText As String
Dim oSl As Slide

If Presentations.Count = 0 Then
    MsgBox "Open a presentation then try again"
    Exit Sub
End If

' EDIT THIS TO REFLECT THE NAME AND LOCATION
' OF THE TEXT FILE YOU WANT TO USE:
sFileName = "c:\folder\filename.txt"

iFileNum = FreeFile()
Open sFileName For Input As iFileNum

' Use the current presentation
With ActivePresentation
    Do While Not EOF(iFileNum)
        Line Input #iFileNum, sHeading
        Line Input #iFileNum, sText
        Set oSl = .Slides.Add(.Slides.Count + 1, ppLayoutText)
        With oSl
            ' Relying on shape names is a bit risky but since we've
            ' just created the slide, the defaults should be safe:
            .Shapes("Rectangle 2").TextFrame.TextRange.Text = sHeading
            .Shapes("Rectangle 3").TextFrame.TextRange.Text = sText
        End With
    Loop
End With

Set oSl = Nothing
Close iFileNum

End Sub

See How do I use VBA code in PowerPoint? to learn how to use this example code.

Search terms:


Did this solve your problem? If so, please consider supporting the PPT FAQ with a small PayPal donation.
Page copy protected against web site content infringement by Copyscape Contents © 1995 - 2015 Stephen Rindsberg, Rindsberg Photography, Inc. and members of the MS PowerPoint MVP team. You may link to this page but any form of unauthorized reproduction of this page's contents is expressly forbidden.
Español    Deutsch    Français    Português    Italiano    Nederlands    Greek    Japanese    Korean    Chinese

Supercharge your PPT Productivity with PPTools

content authoring & site maintenance by
Friday, the automatic faq maker (logo)
Friday - The Automatic FAQ Maker

Add new slides with titles and text from a text file
http://www.pptfaq.com/FAQ00661_Add_new_slides_with_titles_and_text_from_a_text_file.htm
Last update 07 June, 2011
Created: