Getting macro list from VBA

V

viter.alex

Hi, I'm once again your guest :)
Does anybody know how to get list of available macroses for
activedocument? I mean ALL macroses from document itself, Normal
template, add-ins. All those macroses I can see pressing Alt+F8.
It's quite simply get macroses (subroutines without arguments) from
document and Normal template.
And how deal with add-ins?
I wrote a subroutine that search macro names in document (Microsoft
VBScript Regular Expressions 5.5 must be loaded in Tools→References):
Sub GetSubroutinesNames()
Dim oVBComp As VBComponent
Dim oVBCodeMdl As codemodule
Dim sCode As String
Dim nCodeLinesCnt As Long
'Objects for regular expressions
Dim oRegExpProc As New RegExp 'RegExp for searching subroutines
names in module code
Dim oRegExpPrivateMdl As New RegExp 'RegExp for searching
uncommented Option Private Module declaration
Dim oSubMatch As Match
Dim oSubMatches As MatchCollection
Dim i As Integer

With oRegExpProc
.Global = True 'Search in all text
.IgnoreCase = True 'Case insensetive
.MultiLine = True 'Multiline text
.Pattern = "^\s?[^private]sub\s(\b.+?\b)\(\)"
End With

With oRegExpPrivateMdl
.Global = False
.IgnoreCase = True
.MultiLine = True
.Pattern = "^\s?Option Private Module"
End With

For Each oVBComp In ThisDocument.VBProject.VBComponents
If oVBComp.Type = vbext_ct_Document Or oVBComp.Type =
vbext_ct_StdModule Then
Debug.Print oVBComp.Name
nCodeLinesCnt = oVBComp.codemodule.CountOfLines
sCode = oVBComp.codemodule.Lines(1, nCodeLinesCnt)
If Not oRegExpPrivateMdl.Test(sCode) Then
Set oSubMatches = oRegExpProc.Execute(sCode)
For Each oSubMatch In oSubMatches
Debug.Print vbTab & oSubMatch.SubMatches(0)
Next
End If
End If
Next
End Sub

It works but only with opened or unprotected documents and templates.
In order to get subroutines from add-in I have to open it as document
but it's very slowly
Help!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top