| Function GetRoutinesCode(sRoutine As String, sFile As String) As String Dim lProj As Long, lComponent As Long Dim lLineNbrOfRoutine As Long Dim lLinesInRoutine As Long 'sRoutine = "email" FindRoutine sFile, sRoutine, lProj, lComponent '"I:\Monitor.xls" 'Debug.Print lProj, lComponent If lProj = 0 Then MsgBox "Project '" & sFile & "' not currently open, current projects are " & vbCrLf & GetProjectFileList Exit Function End If If lComponent = 0 Then MsgBox "'" & sRoutine & "' not found in '" & sFile & "'" Exit Function End If With Application.VBE.VBProjects(lProj).VBComponents(lComponent).CodeModule lLineNbrOfRoutine = .ProcBodyLine(sRoutine, vbext_pk_Proc) lLinesInRoutine = .ProcCountLines(sRoutine, vbext_pk_Proc) GetRoutinesCode = .Lines(lLineNbrOfRoutine, lLinesInRoutine - 1) End With End Function |