Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Ben Ben is offline
external usenet poster
 
Posts: 509
Default delete Userform control programmatically

Have searched on discussion groups and not found what I am looking for.
How do you programmatically delete a Userform control. This is one that I
have created myself through VBA.
Ben
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default delete Userform control programmatically

right click on it in the project explorer in the VBE and select remove.

--
Regards,
Tom Ogilvy

"ben" wrote in message
...
Have searched on discussion groups and not found what I am looking for.
How do you programmatically delete a Userform control. This is one that I
have created myself through VBA.
Ben



  #3   Report Post  
Posted to microsoft.public.excel.programming
Ben Ben is offline
external usenet poster
 
Posts: 509
Default delete Userform control programmatically

yes of course but i wish to do so while the Userform is running not while
designing it. Thank you however.

"Tom Ogilvy" wrote:

right click on it in the project explorer in the VBE and select remove.

--
Regards,
Tom Ogilvy

"ben" wrote in message
...
Have searched on discussion groups and not found what I am looking for.
How do you programmatically delete a Userform control. This is one that I
have created myself through VBA.
Ben




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,163
Default delete Userform control programmatically

Geez, Ben, didn't turn out to be so easy to figure this out, but you got me
curious so I followed the trail and found the answer: You need to add the
VBIDE (Microsoft Visual Basic for Applications Extensibility) reference, and
then:

ThisWorkBook.VBProject.VBComponents.Remove _
ThisWorkBook.VBProject.VBComponents("UserForm1")


"ben" wrote:

Have searched on discussion groups and not found what I am looking for.
How do you programmatically delete a Userform control. This is one that I
have created myself through VBA.
Ben

  #5   Report Post  
Posted to microsoft.public.excel.programming
Ben Ben is offline
external usenet poster
 
Posts: 509
Default delete Userform control programmatically

K. Dales,

I must apologize to everyone, it seems my question was not specific
enough. Let me try again. I want to delete a Control off of a Userform, not
the userform itself, and I wish to do so through VBA not in VBE in design
mode. I did find how to remove all controls, but I wish to do only one at a
time.

"K Dales" wrote:

Geez, Ben, didn't turn out to be so easy to figure this out, but you got me
curious so I followed the trail and found the answer: You need to add the
VBIDE (Microsoft Visual Basic for Applications Extensibility) reference, and
then:

ThisWorkBook.VBProject.VBComponents.Remove _
ThisWorkBook.VBProject.VBComponents("UserForm1")


"ben" wrote:

Have searched on discussion groups and not found what I am looking for.
How do you programmatically delete a Userform control. This is one that I
have created myself through VBA.
Ben



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default delete Userform control programmatically

Assuming the control was added at runtime

Private Sub CommandButton1_Click()
me.Controls.Remove("textbox1")
End Sub


--
Regards,
Tom Ogilvy

"ben" wrote in message
...
K. Dales,

I must apologize to everyone, it seems my question was not specific
enough. Let me try again. I want to delete a Control off of a Userform,

not
the userform itself, and I wish to do so through VBA not in VBE in design
mode. I did find how to remove all controls, but I wish to do only one at

a
time.

"K Dales" wrote:

Geez, Ben, didn't turn out to be so easy to figure this out, but you got

me
curious so I followed the trail and found the answer: You need to add

the
VBIDE (Microsoft Visual Basic for Applications Extensibility) reference,

and
then:

ThisWorkBook.VBProject.VBComponents.Remove _
ThisWorkBook.VBProject.VBComponents("UserForm1")


"ben" wrote:

Have searched on discussion groups and not found what I am looking

for.
How do you programmatically delete a Userform control. This is one

that I
have created myself through VBA.
Ben



  #7   Report Post  
Posted to microsoft.public.excel.programming
Ben Ben is offline
external usenet poster
 
Posts: 509
Default delete Userform control programmatically

Thank you, appreciate the assistance

"Tom Ogilvy" wrote:

Assuming the control was added at runtime

Private Sub CommandButton1_Click()
me.Controls.Remove("textbox1")
End Sub


--
Regards,
Tom Ogilvy

"ben" wrote in message
...
K. Dales,

I must apologize to everyone, it seems my question was not specific
enough. Let me try again. I want to delete a Control off of a Userform,

not
the userform itself, and I wish to do so through VBA not in VBE in design
mode. I did find how to remove all controls, but I wish to do only one at

a
time.

"K Dales" wrote:

Geez, Ben, didn't turn out to be so easy to figure this out, but you got

me
curious so I followed the trail and found the answer: You need to add

the
VBIDE (Microsoft Visual Basic for Applications Extensibility) reference,

and
then:

ThisWorkBook.VBProject.VBComponents.Remove _
ThisWorkBook.VBProject.VBComponents("UserForm1")


"ben" wrote:

Have searched on discussion groups and not found what I am looking

for.
How do you programmatically delete a Userform control. This is one

that I
have created myself through VBA.
Ben




  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,163
Default delete Userform control programmatically

No, ben, I apologize as in retrospect you were clear that you were talking
about a userform control, not the userform itself. But, hey, I found out
something useful, right?

A run-time control can be deleted with .Remove, but the argument is the
index number in the controls collection, which can make it tricky since that
can change - but this seems to work:

i = 0
While i < UserForm1.Controls.Count
If UserForm1.Controls(i).Name = "MyControl" Then
UserForm1.Controls.Remove i
i = i + 1
Wend

Hope this finally gives you what you need!


"ben" wrote:

K. Dales,

I must apologize to everyone, it seems my question was not specific
enough. Let me try again. I want to delete a Control off of a Userform, not
the userform itself, and I wish to do so through VBA not in VBE in design
mode. I did find how to remove all controls, but I wish to do only one at a
time.

"K Dales" wrote:

Geez, Ben, didn't turn out to be so easy to figure this out, but you got me
curious so I followed the trail and found the answer: You need to add the
VBIDE (Microsoft Visual Basic for Applications Extensibility) reference, and
then:

ThisWorkBook.VBProject.VBComponents.Remove _
ThisWorkBook.VBProject.VBComponents("UserForm1")


"ben" wrote:

Have searched on discussion groups and not found what I am looking for.
How do you programmatically delete a Userform control. This is one that I
have created myself through VBA.
Ben

  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default delete Userform control programmatically

This works fine (in a Userform):

Private Sub CommandButton1_Click()

Set ctrl = Me.Controls.Add _
(bstrprogID:="Forms.TextBox.1", _
Name:="TextBox1", Visible:=True)
ctrl.Top = Me.Controls("combobox1").Top + _
Me.Controls("Combobox1").Height + 10
ctrl.Left = Me.Controls("Combobox1").Left


End Sub

Private Sub CommandButton2_Click()
Me.Controls.Remove "Textbox1
End Sub

So it isn't restricted to a numerical index - while not real clear, the help
does say that it is not restricted to a numerical index.

--
Regards,
Tom Ogilvy

"K Dales" wrote in message
...
No, ben, I apologize as in retrospect you were clear that you were talking
about a userform control, not the userform itself. But, hey, I found out
something useful, right?

A run-time control can be deleted with .Remove, but the argument is the
index number in the controls collection, which can make it tricky since

that
can change - but this seems to work:

i = 0
While i < UserForm1.Controls.Count
If UserForm1.Controls(i).Name = "MyControl" Then
UserForm1.Controls.Remove i
i = i + 1
Wend

Hope this finally gives you what you need!


"ben" wrote:

K. Dales,

I must apologize to everyone, it seems my question was not

specific
enough. Let me try again. I want to delete a Control off of a Userform,

not
the userform itself, and I wish to do so through VBA not in VBE in

design
mode. I did find how to remove all controls, but I wish to do only one

at a
time.

"K Dales" wrote:

Geez, Ben, didn't turn out to be so easy to figure this out, but you

got me
curious so I followed the trail and found the answer: You need to add

the
VBIDE (Microsoft Visual Basic for Applications Extensibility)

reference, and
then:

ThisWorkBook.VBProject.VBComponents.Remove _
ThisWorkBook.VBProject.VBComponents("UserForm1")


"ben" wrote:

Have searched on discussion groups and not found what I am looking

for.
How do you programmatically delete a Userform control. This is one

that I
have created myself through VBA.
Ben



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Programmatically set Excel 97 Control Toobar Checkbox object & container name Matt Jensen Excel Programming 19 January 10th 05 07:46 PM
delete row programmatically Pat Excel Programming 2 September 2nd 04 09:11 PM
Programmatically determine if a control is .VISIBLE or not. Toby Erkson Excel Programming 2 April 16th 04 11:51 PM
Excel - adding control programmatically. Alan B[_3_] Excel Programming 3 December 5th 03 04:34 PM
Is it possible to change the Input Range of a Form Control programmatically? dchow Excel Programming 3 November 21st 03 02:10 PM


All times are GMT +1. The time now is 02:54 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"