Sub CopyFromLIMS()
Application.StatusBar = "Searching for files..."
myYear = Range("CurrentYear").Text
With Application.FileSearch
.NewSearch
.LookIn = Range("InputFolder").Text
.SearchSubFolders = False
.Filename = "*_" & myYear & "_*.txt"
'.MatchTextExactly = True
'.FileType = msoFileTypeAllFiles
If .Execute() = 0 Then response = MsgBox("There were no files found.", vbOKOnly, "File Search")
If .Execute() > 0 Then response = MsgBox("There were " & .FoundFiles.Count & " file(s) found. Click OK to proceed or Cancel to quit.", vbOKCancel, "Import and process files...")
If response <> 1 Then Application.StatusBar = False
If response <> 1 Then Exit Sub
'Copy the files from StarLIMS
Set fso = CreateObject("Scripting.FileSystemObject")
For i = 1 To .FoundFiles.Count
Application.StatusBar = "Processing file " & i & " of " & .FoundFiles.Count & "."
myFileName = .FoundFiles(i)
'On Error Resume Next
With fso
.copyfile myFileName, Range("ProcessFolder").Text
End With
Next i
Set fso = Nothing
Application.StatusBar = False
End With
End Sub