【问题标题】:Accessing Textbox value访问文本框值
【发布时间】: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


    【解决方案1】:

    获取文本框值所需的代码是

    oShape.OLEFormat.Object.Value
    

    【讨论】:

      【解决方案2】:
      1. 你必须set the name的形状:

      2. 获取Shape 对象:
        按名称:oShape = oSlide.Shapes("NameOfShape").
        按索引:oShape = oSlide.Shapes(index)

      3. 要访问形状的文本:

        oShape.TextFrame.TextRange.Text
        

      【讨论】:

      • 使用这个,MsgBox (Str(Len(ActivePresentation.Slides(ActivePresentation.SlideShowWindow.View.Slide.SlideIndex).Shapes("TextBox" & CStr(i)).TextFrame.TextRange.Text) ))。但是它仍然无法正常工作
      • 形状“TextBox1”的名称是否存在?
      • 如果不设置名称,则必须使用索引,例如:slide.Shapes(1)
      • 我的幻灯片 2 上肯定有一个对象,其名称为“TextBox1
      • 当我运行我的代码时,我得到四个消息框,一个带有“我存在”,三个带有“我不存在”,正如预期的那样。我只是没有消息框告诉我 textbox1 中文本的长度
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-13
      相关资源
      最近更新 更多