我目前正在使用以下代码打开工作簿并搜索特定字符串:
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
问题是当我打开几个电子表格时似乎存在一些编译器错误(缺少库)。有什么办法可以解决这个问题吗?我只需要将 CodeMod 内容放到可搜索的地方——但问题似乎在于打开工作簿。