Add new slides with titles and text from a text file
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.
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.