Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

accessing and iterating through modules in excel 97 1

Status
Not open for further replies.

tyhand

Programmer
Jul 3, 2002
186
US
hi all,

how can I access the names of all the modules I have in
excel 97.

I have a handful of modules in my VBAProject(Personal.xls) file and am trying to write a code that iterates and returns the name of each module.

I'm using
ThisWorkbook.VBProject.VBComponents
but am stuck as there no 'modules' object collection.

Any help greatly appreciated. Thanks. Peace!

 
The collection you rae interested in is the VBComponents collection, which is comprised of General Modules, Class Modules, UserForms and the document components such as ThisWorkbook, all the worksheets and chartsheets.

The following code lists all the th ecomponents of the active VBProject to the mmediate window.
Code:
Dim VBC, VBComp
Set VBC = Application.VBE.ActiveVBProject.VBComponents
For Each VBComp In VBC
    Debug.Print VBComp.Name, VBComp.Type
Next VBComp
When new VBProjects are created they are assigned a default name of VBAProject, which if left unchanged (which is probably the norm) makes acessing them via code difficult. If you want to work with yur personal .xls without making it the ActiveVBProject, change the project name from VBAProject to say Personal in the properties window. You can then work with it as follows :
Code:
Dim VBC, VBComp
Set VBC = Application.VBE.VBProjects("Personal").VBComponents
For Each VBComp In VBC
    Debug.Print VBComp.Name, VBComp.Type
Next VBComp
If you run any of the above code fragments, you will see each VBComponent has it's own type identifier,
General Module = 1, Class Module = 2, UserForm = 3 and document components are type 100. This makes it easy to work with a specific type of component.

A.C.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top