Sub ss()
Dim i%, j%, R%, C%, arr, str$
Dim arrByte() As Byte
With Sheet1
R = .Cells(Rows.Count, 1).End(3).Row
C = .Cells(1, Columns.Count).End(xlToLeft).Column
arr = .Range(.Cells(1, 1), .Cells(R, C))
For i = 2 To UBound(arr)
For j = 2 To UBound(arr, 2)
Open ThisWorkbook.Path & "\" & arr(1, j) & ".txt" For Binary Access Read As #1
ReDim arrByte(LOF(1) - 1)
Get #1, , arrByte()
Close #1
str = ByteToStr(arrByte, "utf-8")
If InStr(str, arr(i, 1)) Then .Cells(i, j).Interior.Color = vbGreen
Next j
Next i
End With
End Sub
Function ByteToStr(arrByte, strCharset As String) As String
With CreateObject("Adodb.Stream")
.Type = 1
.Open
.Write arrByte
.Position = 0
.Type = 2
.Charset = strCharset
ByteToStr = .Readtext
.Close
End With
End Function |