Home |
Search |
Today's Posts |
#10
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Now it should be OK:
Sub SearchWBsForCode() Dim strTextToFind As String Dim strFolder As String Dim arr Dim i As Long Dim strWB As String Dim VBProj As VBProject Dim VBComp As VBComponent Dim lStartLine As Long Dim lEndLine As Long Dim lFound As Long Dim lType As Long Dim lSkipped As Long Dim oWB As Workbook Dim bOpen As Boolean Dim bNewBook As Boolean strTextToFind = InputBox("Type the text to find", _ "finding text in VBE") If Len(strTextToFind) = 0 Or StrPtr(strTextToFind) = 0 Then Exit Sub End If strFolder = GetDirectory() If Len(strFolder) = 0 Then Exit Sub End If lType = Application.InputBox("Type file type to search" & _ vbCrLf & vbCrLf & _ "1. Only .xls files" & vbCrLf & _ "2. Only .xla files" & vbCrLf & _ "3. Either file type", _ "finding text in VBE", 1, Type:=1) Select Case lType Case 1 arr = RecursiveFindFiles(strFolder, "*.xls", True, True) Case 2 arr = RecursiveFindFiles(strFolder, "*.xla", True, True) Case 3 arr = RecursiveFindFiles(strFolder, "*.xl*", True, True) Case Else Exit Sub End Select With Application .ScreenUpdating = False .EnableEvents = False .DisplayAlerts = False End With For i = 1 To UBound(arr) Application.StatusBar = i & "/" & UBound(arr) & _ " - Searching " & arr(i) strWB = FileFromPath(arr(i)) On Error Resume Next Set oWB = Workbooks(strWB) If oWB Is Nothing Then bOpen = False Workbooks.Open arr(i) Else 'for preventing closing WB's that are open already bOpen = True Set oWB = Nothing End If bNewBook = True For Each VBComp In Workbooks(strWB).VBProject.VBComponents If Err.Number = 50289 Then 'for protected WB's lSkipped = lSkipped + 1 Err.Clear GoTo PAST End If lEndLine = VBComp.CodeModule.CountOfLines If VBComp.CodeModule.Find(strTextToFind, _ lStartLine, _ 1, _ lEndLine, _ -1, _ False, _ False) = True Then If bNewBook = True Then lFound = lFound + 1 bNewBook = False End If Application.ScreenUpdating = True If MsgBox("Workbook: " & arr(i) & vbCrLf & _ "VBComponent: " & VBComp.Name & vbCrLf & _ "Line number: " & lStartLine & _ vbCrLf & vbCrLf & _ "WB's found so far: " & lFound & vbCrLf & _ "Protected WB's skipped: " & lSkipped & _ vbCrLf & vbCrLf & _ "Stop searching?", _ vbYesNo + vbDefaultButton1 + vbQuestion, _ i & "/" & UBound(arr) & _ " - found " & strTextToFind) = vbYes Then With Application .StatusBar = False .EnableEvents = True .DisplayAlerts = True End With With VBComp.CodeModule.CodePane .SetSelection lStartLine, 1, lStartLine, 1 .Show End With Exit Sub End If Application.ScreenUpdating = False End If Next PAST: If bOpen = False Then Workbooks(strWB).Close savechanges:=False End If On Error GoTo 0 Next On Error Resume Next If bOpen = False Then Workbooks(strWB).Close savechanges:=False End If With Application .ScreenUpdating = True .StatusBar = False .EnableEvents = True .DisplayAlerts = True End With MsgBox lFound & " WB's found with " & strTextToFind & " in VBE" & _ vbCrLf & vbCrLf & _ "protected WB's skipped: " & lSkipped, , _ "finding text in VBE" End Sub RBS |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Searching, matching then searching another list based on the match | Excel Discussion (Misc queries) | |||
code in module A to not execute a Worksheet_SelectionChange sub of another module | Excel Discussion (Misc queries) | |||
Run worksheet module code from workbook module? | Excel Programming | |||
Calls from sheet module to ThisWorkbook module | Excel Programming | |||
Variable from a sheet module in a class module in XL XP | Excel Programming |