I have some code that was v helpfully given (thread705-1142361) to import excel files into a database for me (see below) which ran perfectly last quarter, however now i am getting an error as someone has changed the format of their file before sending it to me so it wont import.
as i have 600 files and i dont know which ones have been changed I would like to put something into the error handling bit of the vba that says when the code comes accross a file it cant import pop up a msgbox with the file name and then go onto the next file or alternatively, something that records all bad file names in a table as it finds them and then automatically skips the bad one and tries to import the next one
code -
'This shall find all excel files named File_Name in folder Search_Folder
Function Searching4Excels(ByVal Search_Folder As String)
'ByVal File_Name As String
With Application.FileSearch
.NewSearch
.FileType = 4 'msoFileTypeExcelWorkbooks
'.Filename = File_Name & "*.xls"
.LookIn = Search_Folder
.SearchSubFolders = False
If .Execute > 0 Then
For iCount = 1 To .FoundFiles.Count
'LBound(.FoundFiles) To UBound(.FoundFiles)
Call ImportThisExcel(.FoundFiles(iCount))
Next iCount
Else
MsgBox "No file found in " & Search_Folder, vbCritical + vbOKOnly, "Importing Excels"
End If
End With
End Function
Sub ImportThisExcel(ByVal FilePathName As String)
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, "imported quarterly data", FilePathName, True
End Sub
Any help very much apriciated
as i have 600 files and i dont know which ones have been changed I would like to put something into the error handling bit of the vba that says when the code comes accross a file it cant import pop up a msgbox with the file name and then go onto the next file or alternatively, something that records all bad file names in a table as it finds them and then automatically skips the bad one and tries to import the next one
code -
'This shall find all excel files named File_Name in folder Search_Folder
Function Searching4Excels(ByVal Search_Folder As String)
'ByVal File_Name As String
With Application.FileSearch
.NewSearch
.FileType = 4 'msoFileTypeExcelWorkbooks
'.Filename = File_Name & "*.xls"
.LookIn = Search_Folder
.SearchSubFolders = False
If .Execute > 0 Then
For iCount = 1 To .FoundFiles.Count
'LBound(.FoundFiles) To UBound(.FoundFiles)
Call ImportThisExcel(.FoundFiles(iCount))
Next iCount
Else
MsgBox "No file found in " & Search_Folder, vbCritical + vbOKOnly, "Importing Excels"
End If
End With
End Function
Sub ImportThisExcel(ByVal FilePathName As String)
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, "imported quarterly data", FilePathName, True
End Sub
Any help very much apriciated