Server Threw an Exception on Workbook.Close

jonpyne

New Member
Joined
Sep 19, 2005
Messages
13
I have a simple MS Word macro that opens up MS Excel files, grabs tables or graphs and inserts them into the MS Word file. It works fine on my computer (MS Windows 2000, MS Office 2000 SP3) and some of my colleagues' (MS Windows 2000/XP, MS Office 2000 SP3), but produces a runtime error on others' (MS Windows XP, MS Office 2000 SP3).
On trying to .Close certain files, we get a "Server threw an exception" error: -2147417851 (80010105) on some systems.
Any ideas?
thanks

I can provide more detailed code if need be, but this is the framework ...

Code:
' ... Subroutine
Public objExcel As Excel.Application '... have tried late-binding, with Object
Public objWorkbook As Excel.Workbook
Private ExcelRunning As Boolean

Sub HookExcelObject()
    On Error GoTo ExcelNotRunning
    ExcelRunning = True
    Set objExcel = GetObject(, "Excel.Application")
    Exit Sub
ExcelNotRunning:
    ExcelRunning = False
    Set objExcel = CreateObject("Excel.Application")
End Sub

Sub UnhookExcelObject()
    If Not ExcelRunning Then
        objExcel.Quit
    End If
    Set objExcel = Nothing
End Sub

' ... Main Module, behind a form
Call HookExcelObject

strFile = "c:\file_1.xls"
Set objWorkbook = objExcel.Workbooks.Open(FileName:=strFile, Updatelinks:=False, ReadOnly:=True)
objWorkbook.Sheets(strSheet).Range(strRange).Copy
objWorkbook.Close SaveChanges:=False

strFile = "c:\file_2.xls"
Set objWorkbook = objExcel.Workbooks.Open(FileName:=strFile, Updatelinks:=False, ReadOnly:=True)
objWorkbook.Sheets(strSheet).Range(strRange).Copy
objWorkbook.Close SaveChanges:=False ' <<< CRASH, BANG, WALLOP!

Set objWorkbook = Nothing
Call UnhookExcelObject
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
Sorry to throw this in your face again.
If I halt the code at the .Close line, I can probe the two objects fine.

Code:
? TypeName(objExcel), TypeName(objWorkbook)
Application   Workbook
? objExcel.ActiveWorkbook.Name, objWorkbook.ActiveSheet.Name
my_workbook.xls   my_Sheet
objExcel.Visible = True
objWorkbook.Activate
objWorkbook.Close SaveChanges:=False
<BOOOOOOOM>

objWorkbook.Saved = True
objWorkbook.Close
<BOOOOOOOM>

objExcel.Visible = True
objWorkbook.Close(False)
<BOOOOOOOM>

Does anyone have any ideas at all?
 
Upvote 0

Forum statistics

Threads
1,216,101
Messages
6,128,842
Members
449,471
Latest member
lachbee

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top