Reputation: 65
In my code I am looking for file which name include bcst
but my code is not working. How can I make it work?
For Each mySubFolder In myFolder.SubFolders
Application.ScreenUpdating = False
Set ana = Workbooks.Open("C:\Users\Burak\Desktop\2MacroDegerlendirme.xlsm").Sheets("Sayfa1") 'Hangi sayfaya alınacak?
For Each myFile In mySubFolder.Files
Str = myFile.Name
If InStr(Str, "bcst") >= 0 Then
Upvotes: 2
Views: 121
Reputation: 562
Looking only at this portion of the code, I'm guessing the error is in
If InStr(Str, "bcst") >= 0 Then
InStr takes as first parameter the starting point of the search. Also it returns 0 if the pattern is not found, so it should be
If InStr(1, Str, "bcst") > 0 Then
.
A prettiest alternative would be to use the Like
operator:
If Str Like "*bcst*" Then
Upvotes: 1