Hello
In a production masterbook, i have 10 excel spreadsheets. They have a specific name , like File1_04052022
I'm looking to build a macro that lets me know if THE 10 files exists even if i change the dates in case of future implementations. meaning it should be able to detect File1_05052022
I set up a loop between an array containing the partial names and a loop going through the files in the directory
I tried using Instr but it seems it doesn't serve it's purpose.
Here's the code i used:
Appreciate any help i can get
Thanks in advance.
In a production masterbook, i have 10 excel spreadsheets. They have a specific name , like File1_04052022
I'm looking to build a macro that lets me know if THE 10 files exists even if i change the dates in case of future implementations. meaning it should be able to detect File1_05052022
I set up a loop between an array containing the partial names and a loop going through the files in the directory
I tried using Instr but it seems it doesn't serve it's purpose.
Here's the code i used:
VBA Code:
Sub tester()
Dim FSO As Object
Dim fldr As Object
Dim folder As String
Dim filesnames As Variant
Dim c As Integer
folder = "Inputs taux"
filesnames = Array("File1", "File2","File3","File4","File5","File7","File9","File10")
c = 0
Set FSO = CreateObject("Scripting.FileSystemObject")
Set fldr = FSO.GetFolder("C\Myenv\")
For Each var In filesnames
For Each File In fldr.Files
If InStr(File.Name, var) > 0 Then
c = c + 1
End If
Next
If c = 0 Then
MsgBox (" There is a missing file")
Exit Sub
Else
End If
Next var
If c = 10 Then
Range("J2").Value = "OK"
End If
End Sub
Thanks in advance.