PDA

View Full Version : Solved: Clear Textboxes



perhol
12-28-2007, 01:59 PM
I have made a 4 week workschedual for my work.
In 4 sheets, containing printout-copies, i have made textboxes (28 in each cheet) in wich users are ment to write remarks to the day of the week.
When changing work-periode users are ment to create new printout-copies using a VBA-macro.
I would like this macro to also clear the 28 textboxes without actually deleting them.
How do i do that? : pray2:

Bob Phillips
12-28-2007, 03:02 PM
Public Sub ClearTextboxes()
Dim ctl As OLEObject

For Each ctl In ActiveSheet.OLEObjects

If TypeName(ctl.Object) = "TextBox" Then

ctl.Object.Text = ""
End If
Next ctl
End Sub

perhol
12-28-2007, 03:53 PM
I have found out that the textboxes are in fact shapes.
In the first sheet they are named Text Box 71 through Text Box 101 with a mysterius jump for each seventh, mening that Text Box 78, Text Box 86 and Text Box 94 are not there. This is giving a total of 28 textboxes in each of the 4 sheets.
I have also found out that i can make a code like this
ActiveSheet.Shapes("Text Box 71").Select
Selection.Characters.Text = ""

for each textbox in the sheet, but i hope you can give me a shorter one.
Sorry i did not check thiis out before making this thread.

Bob Phillips
12-28-2007, 04:22 PM
Public Sub ClearTextboxes()
Dim ctl As Shape

For Each ctl In ActiveSheet.Shapes

If ctl.Type = msoTextBox Then

ctl.TextFrame.Characters.Text = ""
End If
Next ctl
End Sub

perhol
12-28-2007, 04:42 PM
Works perfect.
Seames that you solved my problems lately. This is the third in a few dayes.
Thankyou. :bow: