Delete Userform Control with VBA.

AlexanderBB

Well-known Member
Joined
Jul 1, 2009
Messages
1,835
Office Version
  1. 2019
  2. 2016
Platform
  1. Windows
Is this possible?
I found some details here (msg #9) Programmatically remove a control from userform but it wouldn't work for me.
I tried and got Run-time error '-2147024809 (80070057)': Invalid argument.
VBA Code:
    With myForm
        .Controls.Remove "imgPlay0b"
    End With
I have a Userform with 102 controls so some are hard to find. But I do have all their names.
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
You do understand that you can only remove controls that are created in run-time. Right? If imgPlay0b originates from design time, you cannot remove it in run-time.
 
Upvote 0
It's no problem for you. Just add the control in the Initialize event and then delete it when your done with it. Frankly, unless you are dealing with many controls, just changing the visibility might do well enough.
 
Upvote 0
No, I've added all the controls at run time, so they're very hard to find (the way I've done it) with some hidden under Frames etc. So I was hoping to redesign it.
 
Upvote 0
Is there any overhead to adding controls at run time? I'm going to try it out and have this code:
VBA Code:
Set cControl = myForm.Frame1.Controls.Add("Forms.Label.1", "lbl" & Num, False)
    With cControl
        .Width = 42
        .Height = 12
        .Left = 6
        .Font.Name = "Tahoma"
        .Font.Bold = True
        .AutoSize = False
        .WordWrap = True
        .Font.size = 8.25
    End With
Can the above be used for any control, and could someone confirm the progID parameter? I'm can't figure what the ".1" is and I presume Forms.Label means its a label on a Form? Thanks.
 
Upvote 0
Is there any overhead to adding controls at run time? I'm going to try it out and have this code:
I don't know. I do know that I once did a project for a client that did not have Access but wished to emulate Access' continuous forms. I was able to do it using MSForms, adding quite a few controls at run-time without any issues.
 
Upvote 0

Forum statistics

Threads
1,215,054
Messages
6,122,895
Members
449,097
Latest member
dbomb1414

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top