Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在PowerPoint中从VBA中的文本框读取信息_Vba_Powerpoint - Fatal编程技术网

在PowerPoint中从VBA中的文本框读取信息

在PowerPoint中从VBA中的文本框读取信息,vba,powerpoint,Vba,Powerpoint,我昨天刚刚发现了VBA,我玩得很开心,但是我遇到了一个问题:如何读取文本框的内容。它是幻灯片上唯一的文本框,我希望它能够应用于PowerPoint中的所有幻灯片。请让我澄清这是否有意义 --编辑-- 基本上,我想阅读文本框的内容,就这么简单 --编辑-- 这是我目前的代码: Sub answer() Dim lCurrentView As Long Dim myInput As String Dim sld As Slide Set sld = Applicati

我昨天刚刚发现了VBA,我玩得很开心,但是我遇到了一个问题:如何读取文本框的内容。它是幻灯片上唯一的文本框,我希望它能够应用于PowerPoint中的所有幻灯片。请让我澄清这是否有意义

--编辑-- 基本上,我想阅读文本框的内容,就这么简单

--编辑-- 这是我目前的代码:

Sub answer()
    Dim lCurrentView As Long
    Dim myInput As String
    Dim sld As Slide
    Set sld = Application.ActiveWindow.View.Slide
    myInput = sld.Shapes(4).TextFrame.TextRange.Text
    A = InputBox(prompt:="Your Answer:")
    MsgBox (myInput)
    If A = myInput Then
        MsgBox ("Correct!")
        ActivePresentation.SlideShowWindow _
        .View.GotoSlide Int(Rnd * _
        ActivePresentation.Slides.Count) + 1
    Else
        MsgBox ("Sorry, try again...")
    End If
End Sub

尝试运行此宏并在调试窗口中检查结果(按Ctrl+G将其打开)。逐步执行(按F8键)并放置一些断点(按F9键)并检查对象浏览器(选择一个变量并按Shift+F2键)


尝试运行此宏并在调试窗口中检查结果(按Ctrl+G将其打开)。逐步执行(按F8键)并放置一些断点(按F9键)并检查对象浏览器(选择一个变量并按Shift+F2键)


在演示文稿第一张幻灯片的第一个文本框中键入一些文本。然后打开VBA编辑器,在“VBA项目”下单击鼠标右键,然后选择“添加模块”。在新模块中,粘贴以下代码并按下“播放”按钮


在演示文稿第一张幻灯片的第一个文本框中键入一些文本。然后打开VBA编辑器,在“VBA项目”下单击鼠标右键,然后选择“添加模块”。在新模块中,粘贴以下代码并按下“播放”按钮


好的,谢谢你的简单回答,但我现在的问题是:你如何在当前幻灯片上找到文本框内容。(有关我的当前代码,请参见我的编辑)假设幻灯片上只有1个文本框,则可以将
形状(4)
中的4个替换为1。这个数字指的是幻灯片上形状的索引。好的,谢谢你的简单回答,但我现在的问题是:如何在当前幻灯片上找到文本框内容。(有关我的当前代码,请参见我的编辑)假设幻灯片上只有1个文本框,则可以将
形状(4)
中的4个替换为1。此数字表示幻灯片上形状的索引。
Sub Test()
  Dim Sld As Slide, Shp As Shape
  For Each Sld In ActivePresentation.Slides
    For Each Shp In Sld.Shapes
      Select Case Shp.Type
        Case MsoShapeType.msoTextBox
          Debug.Print Sld.Name, Shp.Name, Shp.TextFrame.TextRange.Text
        Case Else
          Debug.Print Sld.Name, Shp.Name, "This is not a text box"
      End Select
    Next Shp
  Next Sld
End Sub
Sub Textbox_reader()
    Dim myInput As String
    myInput = ActivePresentation.Slides(1).Shapes(1).TextFrame.TextRange.Text
    MsgBox (myInput)
End Sub