PDA

View Full Version : Read Text and Output to Powerpoint



max777
06-26-2015, 07:05 PM
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

max777
06-26-2015, 11:46 PM
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


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