我昨天刚刚发现了VBA,我玩得很开心,但我遇到了一个问题:如何读取文本框的内容。它是幻灯片上唯一的文本框,我希望它能够应用于PowerPoint中的所有幻灯片。请要求我澄清这是否没有意义。
--EDIT--基本上,我想读取文本框的内容,就这么简单。
--EDIT--这是我当前的代码:
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
发布于 2014-03-04 09:40:03
尝试运行此宏并在“调试”窗口中检查结果(按Ctrl+G将其打开)。一步一步地执行它(按F8)并放置一些断点(按F9)并检查对象浏览器(选择一个变量并按Shift+F2)
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
发布于 2014-03-04 10:43:44
在演示文稿的第一张幻灯片的第一个文本框中键入一些文本。然后打开VBA编辑器,在"VBAProject“下单击鼠标右键,然后选择”添加模块“。在新模块中,粘贴以下代码并按"play“按钮。
Sub Textbox_reader()
Dim myInput As String
myInput = ActivePresentation.Slides(1).Shapes(1).TextFrame.TextRange.Text
MsgBox (myInput)
End Sub
https://stackoverflow.com/questions/22160883
复制相似问题