【发布时间】:2020-10-26 03:19:25
【问题描述】:
我正在尝试制作一个自动文本框检查器。
我希望它确保每个文本框中至少有 30 个字符,然后才允许用户移动到下一页。如何访问文本框的值?
具体的一段代码
ActivePresentation.Slides(ActivePresentation.SlideShowWindow.View.Slide.SlideIndex).Shapes("TextBox" & CStr(i)).Characters.Text
Public Sub GeneralCheck()
Dim oSh As Shape
Dim i As Integer
Dim TextBoxCounter As Integer
TextBoxCounter = 0
On Error Resume Next
For i = 1 To 4
Set oSh = ActivePresentation.Slides(ActivePresentation.SlideShowWindow.View.Slide.SlideIndex).Shapes("TextBox" & CStr(i))
If Err.Number = 0 Then ' shape exists
MsgBox ("I exist")
MsgBox (Str(Len(ActivePresentation.Slides(2).Shapes("TextBox" & CStr(i)).Characters.Text)))
TextBoxCounter = TextBoxCounter + 1
Else
MsgBox ("I don't exist")
End If
Next i
End Sub
更新:
更改后的代码仍然无法访问 TextBox 的文本。
Set oSh = ActivePresentation.SlideShowWindow.View.Slide.Shapes("TextBox" & CStr(i))
If Err.Number = 0 Then ' shape exists
MsgBox ("I exist")
ShapeLength = ShapeLength + Len(oSh.TextFrame.TextRange.Text)
MsgBox (ShapeLength)
For 循环似乎可以工作。
【问题讨论】:
标签: vba textbox powerpoint