25. juni 2007 - 11:17Der er
8 kommentarer og 1 løsning
Liste over makroer i en Excelmappe
Jeg har en Excelmappe, hvor der efterhånden er ved at være et større antal makroer. Er der nogen måde automatisk at få generet en liste over samtlige public makroer ?
Fantastisk, flot, forrygende og fabelagtigt! de 100 point er dine lerningvba Nedenstående gør hvad jeg ønsker. Man skal bare huske at ændre sikkerhedsnievuet og trække den reference som foreskrives. Sender du et svar ?
Michael
Function ListAllProcsInProject(VBP As VBIDE.VBProject, Procs() As String) As Long ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' ListAllProcsInProject ' This function populates the string array Procs with strings that identify ' a specific procedure. Each element of Procs is a string of the form: ' ModuleName:ProcType:ProcedureName ' You can use the Split function to break this string into separate elements ' using the ':' character as the delimiter. ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Dim VBComp As VBIDE.VBComponent Dim CodeMod As VBIDE.CodeModule Dim LineNum As Long Dim ProcName As String Dim ProcType As VBIDE.vbext_ProcKind Dim ProcTypeString As String Dim ProcNdx As Long Dim ProcCounter As Long Dim ProcString As String
If VBP.Protection = vbext_pp_locked Then Exit Function End If
Erase Procs For Each VBComp In VBP.VBComponents Set CodeMod = VBComp.CodeModule LineNum = CodeMod.CountOfDeclarationLines + 1 ProcName = CodeMod.ProcOfLine(LineNum, ProcType) Do Until LineNum >= CodeMod.CountOfLines ProcNdx = ProcNdx + 1 ReDim Preserve Procs(1 To ProcNdx) Select Case True Case ProcType = vbext_pk_Get ProcTypeString = "GET" Case ProcType = vbext_pk_Let ProcTypeString = "LET" Case ProcType = vbext_pk_Proc ProcTypeString = "PROC" Case ProcType = vbext_pk_Set ProcTypeString = "SET" End Select ProcString = VBComp.Name & ":" & ProcTypeString & ":" & ProcName Procs(ProcNdx) = ProcString ProcCounter = ProcCounter + 1 LineNum = LineNum + CodeMod.ProcCountLines(ProcName, ProcType) + 1 ProcName = CodeMod.ProcOfLine(LineNum, ProcType) Loop Next VBComp
ListAllProcsInProject = ProcCounter
End Function
'You can loop through the Procs array and use the Split function to break each string into its components, as shown in the procedure below.
Sub ListProcsInProject()
Dim Procs() As String Dim ProcCount As Long Dim VBP As VBIDE.VBProject Dim Ndx As Long Dim Arr As Variant Dim ModuleName As String Dim ProcType As String Dim ProcName As String
ProcCount = ListAllProcsInProject(ThisWorkbook.VBProject, Procs) Debug.Print "Procs Found: " & CStr(ProcCount) If ProcCount > 0 Then For Ndx = LBound(Procs) To UBound(Procs) Arr = Split(Procs(Ndx), ":") ModuleName = Arr(LBound(Arr)) ProcType = Arr(LBound(Arr) + 1) ProcName = Arr(LBound(Arr) + 2) Debug.Print "Module: " & ModuleName, "Type: " & ProcType, "Name: " & ProcName Next Ndx Else Debug.Print "No procs found" End If
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.