Question : Access VBA Code with Excel Object Save As just started generating the Automation Error - The server threw an exception.

I have been using the code below (weekly) for the past 2 or 3 years and all of a sudden today a user reported the following error:

-2147417851  Automation Error
The server threw an exception.

This error is generated on the line of code below that saves the workbook .... XLObj.ActiveWorkbook.SaveAs .......

What's strange is it just started happening today and I can run the same code in my development environment and it works without generating that error.  This is an Access 2k front-end application running on Windows XP machines.

Any ideas will be appreciated.

ET

Here is the code ....

'Create the object and instance of Excel
Dim XLObj As Object
Set XLObj = CreateObject("Excel.Application")
'Open the workbook
XLObj.Workbooks.Open ("T:\Aquatrack\Report.xls")
 
'Check to see if the workbook is read only meaning someone else has it open.
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"
    DoCmd.Close acForm, "message1"
    XLObj.Quit
    Set XLObj = Nothing
    Exit Sub
Else
    'Save the workbook so it can be updated as a true Excel workbook
    XLObj.DisplayAlerts = False
    XLObj.ActiveWorkbook.SaveAs FileName:="T:\Aquatrack\Report.xls", FileFormat:=xlExcel7
    XLObj.Quit
    Set XLObj = Nothing
End If

Answer : Access VBA Code with Excel Object Save As just started generating the Automation Error - The server threw an exception.

Seems like the problem is reated to either a conflict between the user profile and the Excel Objects Library or it could be triggered by a Windows/Office update.  For whatever reason ... that line of code simply stop working and started generating that errror.  I could probably have their IT department reinstall Office 2000 and the related service packs on those machines but at this point it's not worth it.  

As it turns out, the source file is actually a HTML file with a .xls extension for which Excel translates to a workbook when it opens it up.  Since that was the only reason for using the Excel Objects (open/save the source file), the other option is to change the import to use a Text HTML file thus bypassing the Excel Object altogether.

This doesn't answer the question as to why that message just started showing up after 2 years but it solves the problem with importing the file.

Thanks for all the comments and replies.

ET
Random Solutions  
 
programming4us programming4us