PowerPoint VBA:打开文本文件并在单独的幻灯片上显示每一行

发布于 2024-10-04 09:38:02 字数 643 浏览 0 评论 0原文

我希望 PowerPoint 打开一个外部文本文件,并在演示文稿的幻灯片 1 上显示该文件的第 1 行,在幻灯片 2 上显示第 2 行,等等。

如果幻灯片的数量大于文本文件中的行数,我会喜欢再次从第 1 行开始。

这是我到目前为止所拥有的(混合代码和伪代码):

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

如何使用 i 引用文本文件中的行,以及执行 if/then 语句的最佳方法是什么?

我们将非常感谢您的帮助!

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 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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

浅忆流年 2024-10-11 09:38:02

请理解我无法为您完成所有事情,但逻辑看起来是这样的:

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

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文