How do i read a text file to update a text box during a show?

M

Max Cross

I wante to update a text box from a file. It needs to run during the show or
at file load up. I am trying to create a quiz show for use at the youth
group and will need to change the questions weekly, so it would be much
easier if I can just update a text file.
 
D

David M. Marcovitz

Luc's suggestion might work for you. Otherwise, you will have to resort
to writing it yourself in VBA. Here is some sample code that will read
three lines from a text file name mytestfile.txt. For slide 2, it will
change shape 1 to be whatever is in the first line, shape 2, to be
whatever is in the second line, and shape 3 to be whatever is in the
third line. Shape 1 could be a text box for the question and shapes 2 and
3 could be boxes for the answers.

This code doesn't provide any error-checking, and it only reads one
question, but if you are going to resort to code, it should get you
started on what you need. It could fairly easily be made more complicated
to loop through a whole file and create slides as needed to put in more
questions, but I don't have time to make this perfect right now. Let us
know if you want to try this, and if you need help with it.

Sub AdjustQuestion()
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Dim fs, f
Dim theQuestion As String
Dim answer1 As String
Dim answer2 As String
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.OpenTextFile("mytestfile.txt", ForReading, TristateFalse)
theQuestion = f.readline
answer1 = f.readline
answer2 = f.readline
ActivePresentation.Slides(2).Shapes(1).TextFrame.TextRange.Text _
= theQuestion
ActivePresentation.Slides(2).Shapes(2).TextFrame.TextRange.Text _
= answer1
ActivePresentation.Slides(2).Shapes(3).TextFrame.TextRange.Text _
= answer2

f.Close
End Sub


David M. Marcovitz
Director of Graduate Programs in Educational Technology
Loyola College in Maryland
Author of _Powerful PowerPoint for Educators_
http://www.loyola.edu/education/PowerfulPowerPoint/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top