View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default Adding controls to a userform at runtime

I've always had better luck to add all the controls that I'll ever need while in
design mode.

But I'll hide the ones I don't need. Then I can use code to show the ones I
need when I need them.

It makes it easier for the code associated with those controls, too.

AlanGriffithKapitiNZ wrote:

I would like to generate various controls on a skeleton userform (eg, the
number may vary with the occasion) and have tried
Private Sub UserForm_activate()
Stop
Dim obj As Object
Set obj = Me
Set obj = obj.Add("MSForms.CommandButton.1", "Butt1", True)

but when the form opens I receive the error message
Runtime error '-2147221005(800401f3':
Invalid class string

What am I doing wrong, please?


--

Dave Peterson