Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
PJ PJ is offline
external usenet poster
 
Posts: 112
Default Way to output list of macros to file

I'm looking for a way to generate a list of all the macros contained within a
workbook. I've found two suggestions online but haven't been able to get
either to work. Is anyone aware of an easy to get the list of names?

PJZ
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Way to output list of macros to file

I went to cpearson website and got this code. You have to change FName in
the code below and do two things in the comments in the code below.

1) Add the reference library
2) change your macro security.


Sub DeleteAllVBACode()
'1) add following library as reference
'using tools - references
'Microsoft Visual Basic for Applications Extensibility 5.3

'2) Next, you need to enable programmatic access to the VBA Project.
'In Excel 2003 and earlier,
'go the Tools menu (in Excel, not in the VBA editor),
'choose Macros and then the Security item.
'In that dialog, click on the Trusted Publishers tab and
'check the Trust access to the Visual Basic Project setting.

Dim VBProj As VBIDE.VBProject
Dim VBComp As VBIDE.VBComponent
Dim CodeMod As VBIDE.CodeModule
Dim ProcKind As VBIDE.vbext_ProcKind

Set sht = ThisWorkbook.ActiveSheet
FName = "d:\Visual Basic\text.xls"
Set bk = Workbooks.Open(Filename:=FName)
Set VBProj = bk.VBProject
RowCount = 1
For Each VBComp In VBProj.VBComponents

Set CodeMod = VBComp.CodeModule
With CodeMod
LineNum = .CountOfDeclarationLines + 1
ProcName = .ProcOfLine(LineNum, ProcKind)
Do Until LineNum = .CountOfLines
sht.Range("A" & RowCount) = ProcName
sht.Range("B" & RowCount) = ProcKindString(ProcKind)
RowCount = RowCount + 1

LineNum = LineNum + .ProcCountLines(ProcName, ProcKind) + 1

ProcName = .ProcOfLine(LineNum, ProcKind)
Loop
End With

Next VBComp
bk.Close savechanges:=False
End Sub
Function ProcKindString(ProcKind As VBIDE.vbext_ProcKind) As String
Select Case ProcKind
Case vbext_pk_Get
ProcKindString = "Property Get"
Case vbext_pk_Let
ProcKindString = "Property Let"
Case vbext_pk_Set
ProcKindString = "Property Set"
Case vbext_pk_Proc
ProcKindString = "Sub Or Function"
Case Else
ProcKindString = "Unknown Type: " & CStr(ProcKind)
End Select
End Function


"PJ" wrote:

I'm looking for a way to generate a list of all the macros contained within a
workbook. I've found two suggestions online but haven't been able to get
either to work. Is anyone aware of an easy to get the list of names?

PJZ

  #3   Report Post  
Posted to microsoft.public.excel.programming
PJ PJ is offline
external usenet poster
 
Posts: 112
Default Way to output list of macros to file

Hi Joel,

That looks a little different then the code I already tried so it's worth a
shot. I will test it out when I get back to work on Monday.

Thank you.

"joel" wrote:

I went to cpearson website and got this code. You have to change FName in
the code below and do two things in the comments in the code below.

1) Add the reference library
2) change your macro security.


Sub DeleteAllVBACode()
'1) add following library as reference
'using tools - references
'Microsoft Visual Basic for Applications Extensibility 5.3

'2) Next, you need to enable programmatic access to the VBA Project.
'In Excel 2003 and earlier,
'go the Tools menu (in Excel, not in the VBA editor),
'choose Macros and then the Security item.
'In that dialog, click on the Trusted Publishers tab and
'check the Trust access to the Visual Basic Project setting.

Dim VBProj As VBIDE.VBProject
Dim VBComp As VBIDE.VBComponent
Dim CodeMod As VBIDE.CodeModule
Dim ProcKind As VBIDE.vbext_ProcKind

Set sht = ThisWorkbook.ActiveSheet
FName = "d:\Visual Basic\text.xls"
Set bk = Workbooks.Open(Filename:=FName)
Set VBProj = bk.VBProject
RowCount = 1
For Each VBComp In VBProj.VBComponents

Set CodeMod = VBComp.CodeModule
With CodeMod
LineNum = .CountOfDeclarationLines + 1
ProcName = .ProcOfLine(LineNum, ProcKind)
Do Until LineNum = .CountOfLines
sht.Range("A" & RowCount) = ProcName
sht.Range("B" & RowCount) = ProcKindString(ProcKind)
RowCount = RowCount + 1

LineNum = LineNum + .ProcCountLines(ProcName, ProcKind) + 1

ProcName = .ProcOfLine(LineNum, ProcKind)
Loop
End With

Next VBComp
bk.Close savechanges:=False
End Sub
Function ProcKindString(ProcKind As VBIDE.vbext_ProcKind) As String
Select Case ProcKind
Case vbext_pk_Get
ProcKindString = "Property Get"
Case vbext_pk_Let
ProcKindString = "Property Let"
Case vbext_pk_Set
ProcKindString = "Property Set"
Case vbext_pk_Proc
ProcKindString = "Sub Or Function"
Case Else
ProcKindString = "Unknown Type: " & CStr(ProcKind)
End Select
End Function


"PJ" wrote:

I'm looking for a way to generate a list of all the macros contained within a
workbook. I've found two suggestions online but haven't been able to get
either to work. Is anyone aware of an easy to get the list of names?

PJZ

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
Four macros, one main output LiAD Excel Worksheet Functions 2 March 30th 09 07:39 AM
Multiple Macros at once different output Whois Clinton Excel Programming 5 July 30th 08 07:38 PM
Open CSV file, format data and write output to a text file. BristolBloos Excel Programming 1 October 18th 05 03:50 PM
Ooh .. Linking a list to a list to an output cell StrawDog Excel Discussion (Misc queries) 4 August 22nd 05 09:51 PM
Can macros output to a cell selected prior to running it? winnie Excel Worksheet Functions 3 February 17th 05 11:03 PM


All times are GMT +1. The time now is 01:33 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"