PDA

View Full Version : -2147417848 Object Disconnedted from client



davisaggie
04-04-2007, 01:32 PM
I have a user form that builds a workbook from one template sheet and information in a SQL Server database. The template sheet contains 4 charts that are copied to every new sheet in the workbook, then their data ranges are set through VBA code. For a while the code was working wonderfully. All the necessary sheets were being generated and correctly populated.

Yesterday I added a new module to generate another sheet and pull data from the same SQL Server tables. Now if I run the userform it will work fine once and create all the needed sheets, and set all the charts to the proper ranges. However, if I delete all the created sheets and run the form again, I get:

Runtime Error '-2147417848 (80010108)'

Automation Error
The Object Invoked has disconnected from its clients

The error consistantly occurs for the following line of code:
Selection.Copy Destination:=Worksheets("Master").Range("D1")

After the error the selected range still shows up as surrounded by a selection box, but if I change sheets, the box moves to the new sheet. Also I cannot select any new cells in the work book. In order to get Excel to work again I have to End Task from the Task Manager just to get it to close. When I restart Excel and go back to my work book I get the same results, i.e. The form works great once, then Excel dies.

I have been able to narrow it down to the following code which was copied from macros that worked with no problem in the past:

Range("D1").End(xlToRight).Select
Set celladd = Selection.End(xlDown)
Set fillrange = Range("D4", celladd.Offset(1, 0))
Range("D4").Formula = "=IF(AND($C4>=D$2,$C4<=D$3),1,0)"
Range("D4").AutoFill Destination:=fillrange
Set celladd = celladd.Offset(1, 0)
title = celladd.Offset(-2, 0).Address()
celladd.Formula = "=IF($C4>=" & title & ",1,0)"

Any ideas as to what is causing the problem?