Textbox text (Shape)

Krishnakumar

Well-known Member
Joined
Feb 28, 2003
Messages
2,615
Hi All,

How can I store the characters of a textbox (Shape) in a variable?

Any help would be appreciated.
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Try this

Code:
Sub test()
Dim mytext As String
mytext = Sheets("Sheet1").TextBoxes("Text Box 1").Text
MsgBox mytext
End Sub
 
Upvote 0
Hi, Vog,

Thanks for the reply. But the problem is it only returns 255 characters.

How can I store all the characters?
 
Upvote 0
You have to loop unfortunately:
Code:
   Dim mytext As String
   Dim tb As TextBox
   Dim lngIndex As Long
     Set tb = ActiveSheet.TextBoxes("Text Box 1")
    With tb
        For lngIndex = 1 To .Characters.Count Step 255
            mytext = mytext & .Characters(lngIndex, 255).Text
        Next
    End With
    MsgBox mytext
 
Upvote 0
A decade late but figured I'd pass on my solution as well, for VBA Word Wrap.

Defaults to width of 115 but you can optionally specify whatever. Split with CR + LF.


Code:
    Public Function wrapText(strIn As String, Optional maxLen As Long = 110) As String
        Dim p As Long: wrapText = strIn
        Do
            p = InStrRev(wrapText, " ", p + maxLen) - 1
            wrapText = Left(wrapText, p) & vbCrLf & Right(wrapText, Len(wrapText) - p - 1)
        Loop While p + maxLen < Len(wrapText)
    End Function
 
Last edited by a moderator:
Upvote 0

Forum statistics

Threads
1,214,827
Messages
6,121,818
Members
449,049
Latest member
cybersurfer5000

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top