clearing text from text boxes

J

Jae

Can someone instruct me on how to create a macro that clears text out of text
boxes (from the control toolbox) please? Thanks in advance.
 
B

Bob Phillips

As an example

activesheet.oleobjects("TextBox1").object.text=""

--

HTH

RP
(remove nothere from the email address if mailing direct)
 
J

Jae

Hi Bob,

I'm not too familiar with VBA. Can you show me what syntax I need to get
this to work?

Thanks again,

Jae
 
C

Chip Pearson

Jae,

The syntax is exactly what Bob posted. E.g.,

Sub AAA()
activesheet.oleobjects("TextBox1").object.text=""
End Sub

Change the "TextBox1" to the name of your text box control.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
 
C

Chip Pearson

No, you can't clear them out with a single line of code. You'll
have to loop through them. For example,

Sub ClearTextBoxes()
Dim OLEObj As OLEObject
For Each OLEObj In ActiveSheet.OLEObjects
If TypeOf OLEObj.Object Is msforms.TextBox Then
OLEObj.Object.Text = ""
End If
Next OLEObj
End Sub


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
 
Top