I have a workbook that's generated form a website and needs to be imported into Access 2000. However the workbook is created, Access will not import it with a message something like "incorrect format, etc.). But, if I manually open the worksheet and save it as a M/S Excel 97-2000 workbook then Access can import it. Therefore, in VBA code all I need to do is open the workbook and save it as FileFormat xlExcel8.
The code below produces the run-time error 1004 "SaveAs method of workbook class failed" on the
XLObj.ActiveWorkbook.SaveA
s line.
Function FixFile()
Dim XLObj As Object
Set XLObj = CreateObject("Excel.Applic
ation")
XLObj.Workbooks.Open ("T:\TTData\Report.xls")
'Check to see if the workbook is read only
If XLObj.Workbooks("Report.xl
s").ReadOn
ly = True Then
MsgBox "The Workbook is Read-Only and cannot be imported until closed, Import Cancelled!!!", vbCritical, "Import Error"
XLObj.Quit
Set XLObj = Nothing
Exit Function
Else
XLObj.DisplayAlerts = False
XLObj.ActiveWorkbook.SaveA
s FileName:="T:\TTData\Repor
t.xls", FileFormat:=xlExcel8
XLObj.Quit
Set XLObj = Nothing
End If
End Function
Any ideas will be appreciated.
Thanks,
ET
Start Free Trial