-
Notifications
You must be signed in to change notification settings - Fork 5
/
vbEditor.bas
65 lines (48 loc) · 2.04 KB
/
vbEditor.bas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
'
' Needs the »Microsoft Visual Basic for Applications Extensibility 5.3« reference (for vbProject etc)
'
' thisWorkbook.VBProject.references.addFromGuid GUID :="{0002E157-0000-0000-C000-000000000046}", major := 5, minor := 3
'
option explicit
sub findTextInCode(text as string, optional wholeWord as boolean = false, optional matchCase as boolean = false, optional patternSearch as boolean = false) ' {
'
' Note: matchCase and patternSearch cannot both be true.
'
dim proj as vbIDE.vbProject
for each proj in application.vbe.vbProjects
if proj.protection <> vbext_pp_locked then ' {
dim comp as vbIDE.vbComponent
for each comp in proj.vbComponents
dim mdl as vbIDE.codeModule
set mdl = comp.codeModule
dim startLine as long
dim startCol as long
dim endLine as long
dim endCol as long
'
' The following four values are modified by the .find() procedure below (they're passed "byRef")
'
startLine = 1
startCol = 1
endLine = mdl.countOfLines
endCol = -1
do while mdl.find( text, startLine, startCol, endLine, endCol, wholeWord, matchCase, patternSearch ) ' {
dim projFilename as string
' on error resume next
projFilename = proj.filename
' on error goto 0
' if proj.type <> vbext_pt_hostProject then
' projFilename = proj.filename
' else
' projFilename = "..."
' end if
debug.print("found a match at " & projFileName & " - " & comp.name & " - " & startLine & ":" & startCol)
startLine = endLine
startCol = endCol
endLine = mdl.countOfLines
endCol = -1
loop ' }
next comp
end if ' }
next proj
end sub ' }