0
votes

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.

1
What is the specific error you're getting? Do you have any extra References that you've added that won't be persisting to this instance of Excel?Kevin Pope
Its a missing library reference that my machine does not have.mezamorphic
To ignore errors, you can put On Error GoTo 0 in the procedure in question to ignore errors. sourceKevin Pope

1 Answers

0
votes

You need to have the Microsoft Visual Basic for Applications Extensibility reference added in order to run your code.

Tools > References > Then check it and click ok.