1.当文本控件为组合状态下,office 使用一下代码是可以获取到文本框内容

'获取文本控件中的日期
Dim textBox As Object
Dim textBoxValue As String
' 获取文本控件对象
Set textBox = sht1.OLEObjects("TextBox1")
' 获取文本控件中的值
textBoxValue = textBox.Object.Text
2\但WPS获取值textBoxValue 为空,且报无效的过程或参数。
解决方法:首先:组合的控件,取消组合。
最后:
将代码修改为:
' 获取文本框控件中的值
Dim textBoxValue As String
textBoxValue = GetTextBoxValue(sht1, “TextBox10”)
Debug.Print (textBoxValue)
Function GetTextBoxValue(ws As Worksheet, textBoxName As String) As String
Dim oleObj As Object
For Each oleObj In ws.OLEObjects
If oleObj.Name = textBoxName Then
GetTextBoxValue = oleObj.Object.Text
Exit Function
End If
Next oleObj
GetTextBoxValue = “”
End Function
本文介绍了在Excel中,如何在Office环境下正确获取组合状态的文本框内容,以及在WPS中遇到的问题和解决方法,涉及VBA函数GetTextBoxValue的使用。
9638

被折叠的 条评论
为什么被折叠?



