View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
MSP77079[_34_] MSP77079[_34_] is offline
external usenet poster
 
Posts: 1
Default Import and Rename Files

Try this. It's not EXACTLY what you are looking for, but should stee
you in the right direction.

With Application.FileSearch
.LookIn = ThisPath
If .LookIn < ThisPath Then
'if the directory named in cell F1 does not exist, we wil
print
'an error message, then give user an opportunity to navigate t
the
'correct directory
MsgBox "Could not find the directory indicated"
ErrorCode = "bad file"
GoTo GetDirectoryPath
Else:
GoTo LookForFiles
End If
End With

LookForFiles:
'the next few lines of code will ensure that the workbook exists i
that directory

With Application.FileSearch
.LookIn = ThisPath 'directory path
.Filename = "*.xls"
.SearchSubFolders = False

If .Execute() 0 Then
For i = 1 To .FoundFiles.Count
If BlankFormBook = .FoundFiles(i) Then GoT
CheckWorkSheets
Next i
Else
MsgBox "There were no files found in " & ThisFilePath
vbCritical
ErrorCode = "bad file"
GoTo GetDirectoryPath
End If
NumberOfFilesFound = .FoundFiles.Count
End Wit

--
Message posted from http://www.ExcelForum.com