![]() |
|
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Join Date: May 2002
Location: Pune, India
Posts: 2
|
Hello,
I want a list of Macros associated with an Excel Workbook by creating an object of Excel in VB. Can anyone please help. -Murtuza. |
|
|
|
|
|
#2 |
|
Join Date: Apr 2002
Location: Cape Town,South Africa
Posts: 234
|
Good One.
Maybe some of the others can also use this one Dave Hawley can correct me if I am wrong,but they have a brilliant website with a bunch of neat VBA's www.ozgrid.com Not 100% sure of the address,but there it is. ========= Have fun with it |
|
|
|
|
|
#3 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Central Florida, USA
Posts: 7,532
|
This will only display the number of projects, workbook macro work areas, in your workbook. Hope its gets you started. JSW
Sub myMac() 'Run from module. 'Will display the number of macro-work-areas(Projects in workbook). MsgBox "Workbook contains [" & Application.VBE.ActiveVBProject.Collection.Count _ & "] Macro work areas!" End Sub |
|
|
|
|
|
#4 |
|
Join Date: May 2002
Location: Pune, India
Posts: 2
|
Well Joe, this code is something different. This code does not even returns the number of Macros present. But even I get number of macros correct, its not going to solve my problem, I need the names.
I have searched a lot on net but no success. I never knew I have asked such a tricky question !!! |
|
|
|
|
|
#5 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Central Florida, USA
Posts: 7,532
|
The code does not return the number of macros it gets all the macro work areas as a count, so you know how many areas will need to be searched for your macros! JSW
|
|
|
|
|
|
#6 | |
|
MrExcel MVP
Join Date: Feb 2002
Location: Auckland, New Zealand
Posts: 4,208
|
Quote:
This example may help you out. I gather you have the references set up in your VB Project. Sub Commandbutton() Dim xlApp As Object Dim VBCodeMod As CodeModule Dim StartLine As Long Dim ProcName As String Dim VBComp Set xlApp = GetObject("C:ExcelFilesUseful###.xls") ' Make it visible... 'xlApp.Visible = True '// Set references Dim xlModule As Object Set xlModule = xlApp.VBProject.VBComponents For Each VBComp In xlModule Set VBCodeMod = xlApp.VBProject.VBComponents(VBComp.Name).CodeModule If VBComp.Type = 1 Or VBComp.Type = 100 Then With VBCodeMod StartLine = .CountOfDeclarationLines + 1 Do Until StartLine >= .CountOfLines MsgBox .ProcOfLine(StartLine, vbext_pk_Proc) StartLine = StartLine + .ProcCountLines(.ProcOfLine(StartLine, _ vbext_pk_Proc), vbext_pk_Proc) Loop End With End If Set VBCodeMod = Nothing Next VBComp ' Remember to release module Set xlModule = Nothing Set xlApp = Nothing ' Clean up End Sub |
|
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|