HOW TO SELECT THE TEXT BOX?

E

ezil

My application needs copying text box contents (eg.text box 1) from sheet 1
to antoher text box in sheet 2. For that i tried to select text box but i
found it is not possible. What is the code for this task? (The text box is
ordinary text box and not the text box from active control or form control)
 
J

JP Ronse

Hi,

Do you mean a textbox from the drawing toolbar?

Try

Activesheet.shapes.count, this should return the number of shapes in the
worksheet.

Next, you can get the names of the shapes with

activesheet.shapes(x).name with x is a number between 1 and the result of
the .count instruction.

To select: activesheet.shapes(x).select

With
selection.characters.text you can read or set the text.

Something as

Sub AAAA
Dim str As String

With ActiveSheet
.Shapes("Text Box 3").Select
str = Selection.Characters.Text
.Shapes("Text Box 2").Select
Selection.Characters.Text = str
End With

End Sub


should do what you want.

Wkr,

JP
 
R

Rick Rothstein

Try it like this...

Worksheets("Sheet2").TextBoxes("Text Box 1").Text = _
Worksheets("Sheet1").TextBoxes("Text Box 1").Text

where you would use the appropriate worksheet names in place of my "Sheet1"
and "Sheet2" example names and the appropriate Text Box names in place of my
example "Text Box 1" and "Text Box 2".
 
R

Rick Rothstein

By the way, if you are unsure of how to get the names Excel assigns to its
Shape objects (whether they be Text Boxes or any other shape object), simply
select the shape object and then execute this statement in the VB editor's
Immediate window...

? Selection.Name
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top