title: Powerpoint inserting text from external TXT file between slides
body: <p>I have been using the code below (not my code) with success to have users open a presentation and from the title slide, be able to select a .txt file from any location on their computer and have Powerpoint import the text into the Powerpoint and create the slides adhering to the master slide formatting I have set. </p>
  
  <pre><code>Sub AddSlides(text As String)
  Dim Pre As Presentation
  Dim Sld As Slide
  
  Set Pre = ActivePresentation
  Set Sld = Pre.Slides.Add(Index:=Pre.Slides.Count + 1, Layout:=1)
  Sld.Shapes(1).TextFrame.TextRange = text
  End Sub
  
  Sub ReadFile(sFileName As String)
  
  Dim iFileNum As Integer
  Dim sBuf As String
  
  ' edit this:
  'sFileName = "test.csv"
  
  ' does the file exist?  simpleminded test:
  If Len(Dir$(sFileName)) = 0 Then
      Exit Sub
  End If
  
  iFileNum = FreeFile()
  Open sFileName For Input As iFileNum
  
  Do While Not EOF(iFileNum)
      Line Input #iFileNum, sBuf
      AddSlides (sBuf)
  Loop
  
  ' close the file
  Close iFileNum
  
  End Sub
  
  Sub SelectFile()
  
  Dim In_file As Variant
  
  Dim dlgOpen As FileDialog
  Set dlgOpen = Application.FileDialog(Type:=msoFileDialogOpen)
  
  dlgOpen.AllowMultiSelect = False
  
  If dlgOpen.Show = -1 Then
  In_file = dlgOpen.SelectedItems.Item(1)
  ReadFile (In_file)
  End If
  
  End Sub
  </code></pre>
  
  <p>However, now I would like to work with sections, effectively creating a title and a conclusion slide. Section 1 would include the title slide and button for users to select their .txt file. Section 2 would consist of a single slide that concludes the presentation. My problem is, when the code generates the slides from the .txt file, it places them after the conclusion slide in Section 2 instead of after the title slide in Section 1. </p>
  
  <p>I have researched various codes for working with sections and codes for importing/inserting from external files and have had no success working with them to achieve this.</p>
  
  <p>Although I wanted the number of slides generated between the first and last slides to be variable, I can specify how many slides can be generated if this is more feasible. If this does need to be specified, I would also be comfortable creating the slides first and have them populated with the text from the .txt file if this is a more workable option.</p>
  
  <p>Appreciate any help with this.</p>
  
  <p>Note: Current code limits text import to single lines on each slide. If there is a simple way to append this to include 2 lines per slide - that would be extremely useful.</p>