Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Rob Rob is offline
external usenet poster
 
Posts: 718
Default List Modules in a user form

I am trying to create a user form that will display a selectable list of
available modules within a VBAproject in excel.

How do I return a list of modules?

Thanks
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default List Modules in a user form

Rob,

You can use code like the following. In VBA, go to the Tools menu, choose
References, and scroll down to and check "Microsoft Visual Basic For
Applications Extensibility 5.3". This library defines the objects that make
up the components of a VBA Project.


Private Sub CommandButton1_Click()

Dim VBComp As VBIDE.VBComponent

With Me.ListBox1
.Clear
For Each VBComp In ThisWorkbook.VBProject.VBComponents
.AddItem VBComp.Name
Next VBComp
.ListIndex = 0
End With

End Sub

This is the Click event procedure for a button named CommandButton1. It
assumes your list box is named ListBox1. Change the names as you see fit.

See www.cpearson.com/Excel/VBE.aspx for much more information about using
code to manipulate objects and code in the VBA editor.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting
www.cpearson.com
(email on the web site)


"Rob" wrote in message
...
I am trying to create a user form that will display a selectable list of
available modules within a VBAproject in excel.

How do I return a list of modules?

Thanks


  #3   Report Post  
Posted to microsoft.public.excel.programming
Rob Rob is offline
external usenet poster
 
Posts: 718
Default List Modules in a user form

Thank you Chip. Your code example got me pointed in the right direction. The
code you supplied produced a list of all items (Forms, Sheets, etc...). The
following code returns only the Modules.

Dim VBComp As VBIDE.VBComponent
With lst_Modules
.Clear
For Each VBComp In ThisWorkbook.VBProject.VBComponents
If VBComp.Type = vbext_ct_StdModule Then
.AddItem VBComp.Name
End If
Next VBComp
.ListIndex = 0
End With

"Chip Pearson" wrote:

Rob,

You can use code like the following. In VBA, go to the Tools menu, choose
References, and scroll down to and check "Microsoft Visual Basic For
Applications Extensibility 5.3". This library defines the objects that make
up the components of a VBA Project.


Private Sub CommandButton1_Click()

Dim VBComp As VBIDE.VBComponent

With Me.ListBox1
.Clear
For Each VBComp In ThisWorkbook.VBProject.VBComponents
.AddItem VBComp.Name
Next VBComp
.ListIndex = 0
End With

End Sub

This is the Click event procedure for a button named CommandButton1. It
assumes your list box is named ListBox1. Change the names as you see fit.

See www.cpearson.com/Excel/VBE.aspx for much more information about using
code to manipulate objects and code in the VBA editor.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting
www.cpearson.com
(email on the web site)


"Rob" wrote in message
...
I am trying to create a user form that will display a selectable list of
available modules within a VBAproject in excel.

How do I return a list of modules?

Thanks


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
list box on user form KJL Excel Programming 0 March 28th 07 02:02 AM
VBA & User Form modules vanish Pete[_27_] Excel Programming 6 July 10th 06 03:16 AM
User Form List Box Hank Hendrix Excel Programming 0 May 25th 04 10:22 AM
User Form / List Box Rockee052 Excel Programming 0 December 28th 03 04:55 AM
Creating a list box in a user form Heather[_6_] Excel Programming 0 September 30th 03 09:34 PM


All times are GMT +1. The time now is 09:13 PM.

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

About Us

"It's about Microsoft Excel"