I am currently using the following code to open workbooks and search for particular strings:
Set workbook = Application.Workbooks.Open(Path)
Set VBProj = workbook.VBProject
Set oComp = VBProj.VBComponents("Module1")
Set CodeMod = oComp.CodeModule
FindWhat = ToFindStr
With CodeMod
SL = 1
EL = .CountOfLines
SC = 1
EC = 255
Found = .Find(target:=FindWhat, StartLine:=SL, StartColumn:=SC, _
EndLine:=EL, EndColumn:=EC, _
wholeword:=True, MatchCase:=False, patternsearch:=False)
Do Until Found = False
Print #fnum1, "found"
EL = .CountOfLines
SC = EC + 1
EC = 255
Found = .Find(target:=FindWhat, StartLine:=SL, StartColumn:=SC, _
EndLine:=EL, EndColumn:=EC, _
wholeword:=True, MatchCase:=False, patternsearch:=False)
Loop
End With
The problem is there appears to be some compiler errors (missing library) when I open a couple of the spreadsheets. Is there any way I can get around this? I just need to get the CodeMod content to somewhere searchable- but the problem appears to be with opening the workbook.
References
that you've added that won't be persisting to this instance of Excel? – Kevin PopeOn Error GoTo 0
in the procedure in question to ignore errors. source – Kevin Pope