Consulting

Results 1 to 2 of 2

Thread: Read Text and Output to Powerpoint

  1. #1
    VBAX Newbie
    Joined
    Jun 2015
    Posts
    3
    Location

    Read Text and Output to Powerpoint

    I am trying to read a .txt file line by line, and output one line per slide.

    Currently, in my powerpoint, I have one slide and one text box.

    My logic for the vba is that it will create a new slide after reading each line, and print the new line from the .txt file onto the new slide.

    However, I am getting an error on the line.

    Sld.Shapes(1).TextFrame.TextRange.Text = strLine
    Appreciate any help.

    Sub ReadAsciiFile()
        
        Dim Pre As Presentation
        Dim Sld As Slide
        Dim FileName As String
        Dim FileNum As Integer
        Dim i As Integer
        Dim pptLayout As CustomLayout
        
        Set Pre = ActivePresentation
        
        ' edit this:
        FileName = "C:\Users\user\Desktop\veni.txt"
        
        Open FileName For Input As #1
        i = 1
        
        While EOF(1) = False
            Line Input #1, strLine
            
            If Not Len(strLine) = 0 Then
                Set pptLayout = ActivePresentation.Slides(1).CustomLayout
                Set Sld = ActivePresentation.Slides(1)
                Sld.Shapes(1).TextFrame.TextRange.Text = strLine
                Set pptSlide = ActivePresentation.Slides.AddSlide(i + 1, pptLayout)
                i = i + 1
            End If
        Wend
        Close #1
        
    End Sub

  2. #2
    max777
    Guest
    I managed to work it out.

    1. Added the current slide template to Slide Master.
    2. Applied slide template to current slide from Slide Master
    3. Ran the script

    Sub ReadAsciiFile()
         
        Dim Pre As Presentation
        Dim Sld As Slide
        Dim FileName As String
        Dim FileNum As Integer
        Dim i As Integer
        Dim pptLayout As CustomLayout
        Dim NewSld As Shape
         
        Set Pre = ActivePresentation
         
         ' edit this:
        FileName = "C:\Users\User1\Desktop\veni.txt"
         
        Open FileName For Input As #1
    
    
        i = 0
        While EOF(1) = False
            i = i + 1
            Line Input #1, strLine
            If Not Len(strLine) = 0 Then
    
    
                Set Sld = ActivePresentation.Slides(i)
                strLine = StrConv(strLine, vbProperCase)
                Sld.Shapes(1).TextFrame.TextRange = strLine
                MyString = UCase(Left(MyString, 1))
                Set pptLayout = ActivePresentation.Slides(i).CustomLayout
                Set pptSlide = ActivePresentation.Slides.AddSlide(i + 1, pptLayout)
    
    
            End If
        Wend
        Close #1
         
    End Sub
    Quote Originally Posted by max777 View Post
    I am trying to read a .txt file line by line, and output one line per slide.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •