|
楼主 |
发表于 2012-6-11 14:53
|
显示全部楼层
Sub testtttt()
Dim wkst As Worksheet
Set wkst = ActiveSheet
Dim tb As Shape
Set tb = wkst.Shapes("test")
MsgBox Len(textboxread(tb))
End Sub
Function textboxread(ByRef tb As Shape) As String
Dim s As String
Dim numChars As Integer
s = ""
numChars = 255
If tb.TextFrame.Characters.Count < 255 Then
numChars = tb.TextFrame.Characters.Count
Else
Do While tb.TextFrame.Characters.Count > 0
s = s & tb.TextFrame.Characters(1, numChars).text
tb.TextFrame.Characters(1, numChars).Delete
If tb.TextFrame.Characters.Count < 255 Then
numChars = tb.TextFrame.Characters.Count
End If
Loop
textboxread = s
End If
textboxwrite tb, s
Set tb = Nothing
Set wkst = Nothing
End Function
Function textboxwrite(ByRef tb As Shape, s As String)
Dim numChars As Integer, addnum As Integer
numChars = 0
addnum = 255
If Len(s) < 255 Then
tb.TextFrame.Characters.text = s
Else
Do While Len(s) > 0
If numChars < 32767 - addnum Then
tb.TextFrame.Characters(numChars + 1, addnum).Insert (left(s, addnum))
Else
tb.TextFrame.Characters(numChars + 1, 32767 - numChars).Insert (left(s, 32767 - numChars))
GoTo endfunction
End If
numChars = numChars + addnum
s = Right(s, Len(s))
If Len(s) < 255 Then
addnum = Len(s)
End If
Loop
End If
endfunction:
Set tb = Nothing
Set wkst = Nothing
End Function
|
|