Supercharge your PowerPoint productivity with

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

Tell me about PPTools

Add new slides with titles and text from a text file


PPTools
Shape Styles brings the power of styles to PowerPoint. Apply complex formatting with a single click
Merge Excel, CSV or tab-delimited data into PowerPoint presentations to create certificates, awards presentations, personalized presentations and more
FixLinks prevents broken links when you distribute PowerPoint presentations
Optimizer saves disk space and bandwidth, shrinks your PowerPoint presentations to the right size for email, screenshow or printing
PPT2HTML gives you full control of PowerPoint HTML output, helps meet Section 508 accessibility requirements
Prep4PDF preserves interactivity in PowerPoint presentations when you convert to PDF
Image Export converts PowerPoint slides to JPG, PNG, GIF, WMF and more

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:


Page copy protected against web site content infringement by Copyscape Contents © 1995 - 2008 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.htm
Last update 09 September, 2006