0


I googled a lot but I had absolutely no luck finding anything about my problem.

I would like to create ListBox - just like the one anyone can create using UserForms. The problem is that I do not want to draw it but write it with a code. I know how to add values to ListBox etc. The only thing I am missing is how to create it programatically.

I found this: Creating form programmatically in the module using vba but this code didn't work for me. It stops at declaring Forms.

The idea behind this ListBox is to create a ListBox to choose from sheets in a workbook to later do some stuff.

Community
  • 1
  • 1
lowak
  • 1,254
  • 2
  • 18
  • 38
  • 1
    Read up more on `Me.Controls.Add`. See [THIS](http://stackoverflow.com/questions/10224511/assign-code-to-a-button-created-dynamically-using-vba-on-excel) – Siddharth Rout Aug 28 '14 at 10:11

1 Answers1

2
Me.Controls.Add ("Forms.Listbox.1")

allows you to add a control at runtime only using an event procedure.

  • Is this necessary to use Forms? Module alone cannot handle it? – lowak Aug 28 '14 at 10:37
  • hm.. sorry what do you mean? –  Aug 28 '14 at 10:41
  • I was wondering if ListBox can be created without using Forms - UserForm. Because your code will work in Userform but when i paste it to Module it will not. I wanted to write whole code in one place and bypass - if possible - UserForm. – lowak Aug 28 '14 at 10:46
  • Hm. have you seen the `resolution` part of [THIS LINK](http://support.microsoft.com/kb/157319) ? Is that what you are after? –  Aug 28 '14 at 10:48