Sub Sample8()
Dim CodeLine As Long, DeclarationLines As Long
With ThisWorkbook.VBProject.VBComponents("Module1").CodeModule
DeclarationLines = .CountOfDeclarationLines
CodeLine = .CountOfLines
End With
MsgBox "宣言セクションの行数:" & DeclarationLines & vbCrLf & _
"プロシージャの行数:" & CodeLine - DeclarationLines
End Sub
Linesプロパティ
Linesプロパティの書式は次の通りです。
CodeModule.Lines(startline, count)
引数startlineから、引数countで指定した行分のコードを返します。
Sub Sample9()
Dim Code As String
Code = ThisWorkbook.VBProject.VBComponents("Module1").CodeModule.Lines(7, 5)
MsgBox Code
End Sub
Sub Sample14()
Dim buf As String, ProcNames As String, i As Long
With ThisWorkbook.VBProject.VBComponents("Module1").CodeModule
For i = 1 To .CountOfLines
If buf <> .ProcOfLine(i, 0) Then
buf = .ProcOfLine(i, 0)
ProcNames = ProcNames & buf & vbCrLf
End If
Next i
End With
MsgBox ProcNames
End Sub