| Function DeleteRoutine(sRoutine As String, lProj As Long) As Boolean 'Version: 1.000 'Purpose: This routine will delete the passed routine from the selected project pointed to by lProj Dim i As Long, j As Long, sCurr As String, sLine As Long, lLines As Long, sCode As String With Application.VBE.VBProjects(lProj) For i = 1 To .VBComponents.Count 'for each module in a project For j = 1 To .VBComponents(i).CodeModule.CountOfLines 'line in a module sCurr = .VBComponents(i).CodeModule.ProcOfLine(j, vbext_pk_Proc) If sCurr = sRoutine Then sLine = .VBComponents(i).CodeModule.ProcStartLine(sCurr, vbext_pk_Proc) lLines = .VBComponents(i).CodeModule.ProcCountLines(sCurr, vbext_pk_Proc) sCode = .VBComponents(i).CodeModule.Lines(sLine, lLines) 'Save the code somewhere in case of undo is needed 'Delete the current version .VBComponents(i).CodeModule.DeleteLines sLine, lLines DeleteRoutine = True Exit Function End If Next Next End With End Function |