Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 811
Default List the Macros that can be executed from Tools-Macros

"Charles Williams" wrote in message
...
I am looking for a good way of building an array of the Macros that a user
sees when they press Tools--Macros.


Hi Charles,

The functions below provide a quick and dirty method of doing this. Note
that I fail to check whether the code module has the Option Private Module
switch, as this was created for users who weren't going to be that
sophisticated, but that's an easy check to add.

--
Rob Bovey, MCSE, MCSD, Excel MVP
Application Professionals
http://www.appspro.com/

* Please post all replies to this newsgroup *
* I delete all unsolicited e-mail responses *


'''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''''''''
''
''' Comments: Creates a list of all public subroutines located in the
''' specified workbook.
'''
''' Arguments: wkbTarget [in] The workbook whose macros we need to
''' enumerate.
''' aszMacroList() [out] A string array to be loaded with a
list
''' of public subroutines contained in
wkbTarget.
'''
''' Returns: Boolean True if any Public subs were located, False
''' otherwise.
'''
''' Date Developer Action
''' ------------------------------------------------------------------------
--
''' 02/18/03 Rob Bovey Created
'''
Public Function bEnumerateMacros(ByRef wkbTarget As Excel.Workbook, _
ByRef aszMacroList() As String) As Boolean
Dim lIndex As Long
Dim lCodeLine As Long
Dim szProcName As String
Dim szFirstLine As String
Dim modCurrentModule As VBIDE.CodeModule
Dim cmpComponent As VBIDE.VBComponent
Dim cmpComponents As VBIDE.VBComponents
lIndex = -1
Set cmpComponents = wkbTarget.VBProject.VBComponents
For Each cmpComponent In cmpComponents
''' We only care about standard modules.
If cmpComponent.Type = vbext_ct_StdModule Then
Set modCurrentModule = cmpComponent.CodeModule
For lCodeLine = 1 To modCurrentModule.CountOfLines
szProcName = vbNullString
''' Locate any subroutines in this module.
szProcName = modCurrentModule.ProcOfLine(lCodeLine,
vbext_pk_Proc)
If Len(szProcName) 0 Then
''' If this is a public subroutine with no arguments,
add it to the array.
lCodeLine = modCurrentModule.ProcBodyLine(szProcName,
vbext_pk_Proc)
szFirstLine = modCurrentModule.Lines(lCodeLine, 1)
If IsValidSubroutine(szFirstLine) Then
lIndex = lIndex + 1
ReDim Preserve aszMacroList(0 To lIndex)
aszMacroList(lIndex) = szProcName
End If
''' Skip to next procedure
lCodeLine = lCodeLine +
modCurrentModule.ProcCountLines(szProcName, vbext_pk_Proc) - 1
End If
Next lCodeLine
End If
Next cmpComponent
bEnumerateMacros = (lIndex -1)
End Function

'''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''''''''
''
''' Comments: Determines if the specified procedure is a public subroutine
''' with no arguments.
'''
''' Arguments: szFirstLine [in] The first line of the subroutine to
check.
'''
''' Returns: Boolean True if the specified code line contains a
''' valid public sub, False otherwise.
'''
''' Date Developer Action
''' ------------------------------------------------------------------------
--
''' 02/18/03 Rob Bovey Created
'''
Private Function IsValidSubroutine(ByRef szFirstLine As String) As Boolean
Dim lOpenParen As Long
Dim lCloseParen As Long
''' Make sure the procedure is a public subroutine.
If szFirstLine Like "Sub *" Or szFirstLine Like "Public Sub *" Or _
szFirstLine Like "Static Sub *" Or szFirstLine Like "Public Static
Sub *" Then
''' Make sure the subroutine has no arguments.
lOpenParen = InStr(szFirstLine, ")")
lCloseParen = InStrRev(szFirstLine, "(")
IsValidSubroutine = (lOpenParen + 1 = lCloseParen)
End If
End Function



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 968
Default List the Macros that can be executed from Tools-Macros

Hi Rob,

Thanks that looks great .


Charles
______________________
Decision Models
The Excel Calculation Site
www.DecisionModels.com

"Rob Bovey" wrote in message
...
"Charles Williams" wrote in message
...
I am looking for a good way of building an array of the Macros that a

user
sees when they press Tools--Macros.


Hi Charles,

The functions below provide a quick and dirty method of doing this.

Note
that I fail to check whether the code module has the Option Private Module
switch, as this was created for users who weren't going to be that
sophisticated, but that's an easy check to add.

--
Rob Bovey, MCSE, MCSD, Excel MVP
Application Professionals
http://www.appspro.com/

* Please post all replies to this newsgroup *
* I delete all unsolicited e-mail responses *



'''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''''''''
''
''' Comments: Creates a list of all public subroutines located in the
''' specified workbook.
'''
''' Arguments: wkbTarget [in] The workbook whose macros we need to
''' enumerate.
''' aszMacroList() [out] A string array to be loaded with a
list
''' of public subroutines contained in
wkbTarget.
'''
''' Returns: Boolean True if any Public subs were located,

False
''' otherwise.
'''
''' Date Developer Action

''' ------------------------------------------------------------------------
--
''' 02/18/03 Rob Bovey Created
'''
Public Function bEnumerateMacros(ByRef wkbTarget As Excel.Workbook, _
ByRef aszMacroList() As String) As Boolean
Dim lIndex As Long
Dim lCodeLine As Long
Dim szProcName As String
Dim szFirstLine As String
Dim modCurrentModule As VBIDE.CodeModule
Dim cmpComponent As VBIDE.VBComponent
Dim cmpComponents As VBIDE.VBComponents
lIndex = -1
Set cmpComponents = wkbTarget.VBProject.VBComponents
For Each cmpComponent In cmpComponents
''' We only care about standard modules.
If cmpComponent.Type = vbext_ct_StdModule Then
Set modCurrentModule = cmpComponent.CodeModule
For lCodeLine = 1 To modCurrentModule.CountOfLines
szProcName = vbNullString
''' Locate any subroutines in this module.
szProcName = modCurrentModule.ProcOfLine(lCodeLine,
vbext_pk_Proc)
If Len(szProcName) 0 Then
''' If this is a public subroutine with no arguments,
add it to the array.
lCodeLine = modCurrentModule.ProcBodyLine(szProcName,
vbext_pk_Proc)
szFirstLine = modCurrentModule.Lines(lCodeLine, 1)
If IsValidSubroutine(szFirstLine) Then
lIndex = lIndex + 1
ReDim Preserve aszMacroList(0 To lIndex)
aszMacroList(lIndex) = szProcName
End If
''' Skip to next procedure
lCodeLine = lCodeLine +
modCurrentModule.ProcCountLines(szProcName, vbext_pk_Proc) - 1
End If
Next lCodeLine
End If
Next cmpComponent
bEnumerateMacros = (lIndex -1)
End Function


'''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''''''''
''
''' Comments: Determines if the specified procedure is a public

subroutine
''' with no arguments.
'''
''' Arguments: szFirstLine [in] The first line of the subroutine to
check.
'''
''' Returns: Boolean True if the specified code line contains a
''' valid public sub, False otherwise.
'''
''' Date Developer Action

''' ------------------------------------------------------------------------
--
''' 02/18/03 Rob Bovey Created
'''
Private Function IsValidSubroutine(ByRef szFirstLine As String) As Boolean
Dim lOpenParen As Long
Dim lCloseParen As Long
''' Make sure the procedure is a public subroutine.
If szFirstLine Like "Sub *" Or szFirstLine Like "Public Sub *" Or _
szFirstLine Like "Static Sub *" Or szFirstLine Like "Public Static
Sub *" Then
''' Make sure the subroutine has no arguments.
lOpenParen = InStr(szFirstLine, ")")
lCloseParen = InStrRev(szFirstLine, "(")
IsValidSubroutine = (lOpenParen + 1 = lCloseParen)
End If
End Function





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
Keep macros from being ran under the tools option in the menu bar Jeremy Excel Discussion (Misc queries) 3 April 20th 10 08:42 PM
How do I get my macros from an XLA file to show in Tools Macro Harlan Grove[_2_] Excel Worksheet Functions 0 June 28th 09 11:34 PM
How do I get my macros from an XLA file to show in Tools Macro smartin Excel Worksheet Functions 0 June 28th 09 10:48 PM
Macros warning always shows up, even if all macros removed Joe M Excel Discussion (Misc queries) 1 December 20th 07 04:45 AM
how can i make macros to work when in tools, costumize and option. MOLECULA0_0 Excel Worksheet Functions 2 May 18th 06 04:54 AM


All times are GMT +1. The time now is 08:47 AM.

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"