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