I have some code very kindly given to me in thread 705-1142361 It has been working perfectly up to now but following some changes to the import files and therefore to the table that they import into now come up with an error message "Failed to Import File " (as you would expect)
code-
Function Searching4Excels(ByVal Search_Folder As String)
On Error GoTo BadImport
Dim ImportFileName 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)
ImportFileName = .FoundFiles(iCount)
ImportThisExcel ImportFileName
Next iCount
Else
MsgBox "No file found in " & Search_Folder, _
vbCritical + vbOKOnly, "Importing Excels"
End If
End With
Exit Function
BadImport:
Select Case Err.Number
' All the error numbers that may be raised
' by an import failure.
Case 2391 ', 222, 333, ...
MsgBox "Failed to Import File " & ImportFileName
Resume Next
Case Else
' Handle other Errors.
MsgBox Err.Description
End Select
End Function
Is there any way to find out why it wont import and what the problem is as i have checked the field types are the same, fields size etc and cant figure why they wont import
many thanks in hope
code-
Function Searching4Excels(ByVal Search_Folder As String)
On Error GoTo BadImport
Dim ImportFileName 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)
ImportFileName = .FoundFiles(iCount)
ImportThisExcel ImportFileName
Next iCount
Else
MsgBox "No file found in " & Search_Folder, _
vbCritical + vbOKOnly, "Importing Excels"
End If
End With
Exit Function
BadImport:
Select Case Err.Number
' All the error numbers that may be raised
' by an import failure.
Case 2391 ', 222, 333, ...
MsgBox "Failed to Import File " & ImportFileName
Resume Next
Case Else
' Handle other Errors.
MsgBox Err.Description
End Select
End Function
Is there any way to find out why it wont import and what the problem is as i have checked the field types are the same, fields size etc and cant figure why they wont import
many thanks in hope