View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Doug Glancy Doug Glancy is offline
external usenet poster
 
Posts: 770
Default add another text box

Spence,

This is what I came up with:

Private Sub CommandButton1_Click()

Dim ctl As Control
Dim txtbox_top As Integer, txtbox_left As Integer, _
txtbox_height As Integer, txtbox_width As Integer, _
txtbox_count As Integer

txtbox_top = 0
txtbox_left = 10 ' something to start with
txtbox_height = 10
txtbox_width = 20
txtbox_count = 0

For Each ctl In Me.Controls
If TypeName(ctl) = "TextBox" Then
If ctl.Top txtbox_top Then
With ctl
txtbox_top = .Top
txtbox_left = .Left
txtbox_height = .Height
txtbox_width = .Width
End With
End If
txtbox_count = txtbox_count + 1
End If
Next ctl

Set ctl = Me.Controls.Add("Forms.TextBox.1", "TextBox" & txtbox_count + 1)
With ctl
.Top = txtbox_top + 20
.Left = txtbox_left
.Height = txtbox_height
.Width = txtbox_width
End With

End Sub

hth,

Doug

"spence" wrote in message
...
on sheet1 i have commandbotton1
i want to click commandbutton1 and have the macro add a
text box. if text box1's Top property = 20 i want text
box2's Top property to be 40 and textbox3's to be 40 and
so on. i am trying to work with a loop, but cant quite
figure it out, Thanks...spence.