Question : Using Workbook.SaveAs in Access with VBA generates Error 1004???

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.SaveAs  line.

Function FixFile()
Dim XLObj As Object

Set XLObj = CreateObject("Excel.Application")
XLObj.Workbooks.Open ("T:\TTData\Report.xls")
 
'Check to see if the workbook is read only
If XLObj.Workbooks("Report.xls").ReadOnly = 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.SaveAs FileName:="T:\TTData\Report.xls", FileFormat:=xlExcel8
    XLObj.Quit              
    Set XLObj = Nothing    
End If

End Function


Any ideas will be appreciated.

Thanks,

ET

Answer : Using Workbook.SaveAs in Access with VBA generates Error 1004???

Try:

    XLObj.ActiveWorkbook.SaveAs FileName:="T:\TTData\Report.xls", FileFormat:=56

Kevin
Random Solutions  
 
programming4us programming4us