I am having a problem with the following script when I try to transfer an Excel workbook to an Access Table I recieve the following error [Red]"External Table is Not in the Expected Format"[/red]. The script will only works if the excel workbook is open. I am using Access/Excel 2007 version and the workbook has an extension of xlsm.
Could this be a problem with acSpreadsheetTypeExcel12? I need to be able to tranfer the data without having to have the excel workbook open. How do I fix this?
[blue]
Dim oXL As Object
Dim oExcel As Object
Dim sFullPath As String
Dim rs, intMaxCol
Set rs = CurrentDb.OpenRecordset("Inventory", dbOpenSnapshot)
intMaxCol = rs.Fields.Count
If rs.RecordCount > 0 Then
rs.MoveLast:
End If
' Create a new Excel instance
Set oXL = CreateObject("Excel.Application")
' Full path of excel file to open
On Error GoTo ErrHandle
sFullPath = "C:\New Folder\Inventory.xlsm"
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel12, "Inventory", sFullPath, False, "Sheet1 Totals!A1:F20"
End
With oXL
.Visible = False
.Workbooks.Open (sFullPath)
End With
ErrExit:
Set oXL = Nothing
Exit Sub
ErrHandle:
oXL.Visible = False
MsgBox Err.Description
GoTo ErrExit
End Sub
[/blue]
Could this be a problem with acSpreadsheetTypeExcel12? I need to be able to tranfer the data without having to have the excel workbook open. How do I fix this?
[blue]
Dim oXL As Object
Dim oExcel As Object
Dim sFullPath As String
Dim rs, intMaxCol
Set rs = CurrentDb.OpenRecordset("Inventory", dbOpenSnapshot)
intMaxCol = rs.Fields.Count
If rs.RecordCount > 0 Then
rs.MoveLast:
End If
' Create a new Excel instance
Set oXL = CreateObject("Excel.Application")
' Full path of excel file to open
On Error GoTo ErrHandle
sFullPath = "C:\New Folder\Inventory.xlsm"
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel12, "Inventory", sFullPath, False, "Sheet1 Totals!A1:F20"
End
With oXL
.Visible = False
.Workbooks.Open (sFullPath)
End With
ErrExit:
Set oXL = Nothing
Exit Sub
ErrHandle:
oXL.Visible = False
MsgBox Err.Description
GoTo ErrExit
End Sub
[/blue]