PowerPoint VBA: open a text file and show each line on a seperate slide
I want PowerPoint to open an external text file and show line 1 of this file on slide 1 of my presentation, line 2 on slide 2, etc.
If the number of slides is larger than the number of lines in the text file, I would like to start at line 1 again.
Here's what I have so far (mixed code开发者_StackOverflow中文版 and pseudocode):
Dim FileName, FSO, MyFile
FileName = "C:\test.txt"
Set FSO = CreateObject("Scripting.FileSystemObject")
Set MyFile = FSO.OpenTextFile(FileName, 1)
For i = 1 To ActivePresentation.Slides.Count
If LINE(i) EXISTS IN TEXT FILE THEN
ActivePresentation.Slides(i).Shapes("myshape").TextFrame.TextRange.Text = LINE(i)
ELSE START AT LINE(1) AGAIN
End If
Next
MyFile.Close
How do I refer to the lines in the text file using i
, and what would be the best way to do the if/then-statement?
Your help would be greatly appreciated!
Please understand I cannot do the whole thing for you but the logic somehow looks like this:
MoreSlides = true
While moreSlides
Open "mytextfile.txt" For Input As 1
While Not EOF(1) and moreSlides
Line Input #1, myline
' here comes the part inserting the line in the next slide
' You set moreSlides to false if you reach the end
Wend
close #1
Wend
精彩评论