, VBA ( VBIDE API). Microsoft Visual Basic Extentibility 5.3, , CodePane VBComponent:
Sub FindComments()
Dim component As VBComponent
For Each component In Application.VBE.ActiveVBProject.VBComponents
Dim contents As String
contents = component.CodeModule.Lines(1, component.CodeModule.CountOfLines)
'"contents" now contains a string with the entire module code.
Debug.Print ParseComments(contents) 'todo
Next
End Sub
, contents, ... - :
Sub Test()
Dim foo 'this is comment 1
'this _
is _
comment 2
Debug.Print "This 'is not a comment'!"
'..and here comment 3
REM oh and guess what, a REM instruction is also a comment!
Debug.Print foo : REM can show up at the end of a line, given an instruction separator
End Sub
So, you need to iterate over the lines, keep track of whether the comment continues on the next line / continues from the previous line, skip string literals, etc.
Good luck
source
share