Excel sometimes fails with automation error The object invoked has disconnected from its clients

venugopal.p

New Member
Joined
Jun 11, 2010
Messages
3
Hi,

Please help me in fixing the run time error problem

Exact error message is "Run-time error'-2147417848(80010108)':
Automation error
The object invoked has disconnected from its clients"

The above mentioned error comes occasionaly so it makes the macro unstable

What is wrong in the below code which makes that run time error?



Private Sub Worksheet_Change(ByVal Target As Range)
' This sub will help us in getting the workflow name based on the Folder
Dim OXL1 As Excel.Application
Set OXL1 = Excel.Application

OXL1.Application.EnableCancelKey = xlDisabled
OXL1.Application.ScreenUpdating = False
Dim folder, wfname, wfquery, destination As Variant
Dim KeyCells As Range
' The variable KeyCells contains the cells that will
' cause an alert when they are changed.
Set KeyCells = Range("B10")

If Not OXL1.Application.Intersect(KeyCells, Range(Target.Address)) _
Is Nothing Then
wfquery = "SELECT DISTINCT TASK_NAME,LAST_SAVED FROM OPB_TASK A WHERE TASK_TYPE=71 AND SUBJECT_ID IN (SELECT SUBJ_ID FROM OPB_SUBJECT WHERE SUBJ_NAME LIKE '%" & Sheet1.Range("b10").Value & "%' ) ORDER BY LAST_SAVED DESC"
Sheet3.Activate
Sheet3.Range("a1:a65536").Select
Selection.ClearContents
Sheet3.Range("a1").Select
Set destination = Sheet3.Range("a1:a65536")

With OXL1.QueryTables.Add(Connection:=Array(Array( _
"ODBC;DSN=D1EDW;UID=svinft0;PWD=temp;;DBQ=D1EDW;DBA=W;")), destination:=destination _
)
.CommandText = wfquery
.Name = "Query from D1EDW"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshStyle = xlInsertCells
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
.Refresh BackgroundQuery:=False
End With
Sheet1.Activate
Sheet1.Range("d10").Value = " Select a Workflow from Dropdown"
End If
OXL1.Application.ScreenUpdating = True

Set KeyCells = Range("d10")

If Not OXL1.Application.Intersect(KeyCells, Range(Target.Address)) _
Is Nothing Then
If Range("d10").Value = "" Then
MsgBox "Blank values are not allowed"
End If
End If
End Sub
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.

Forum statistics

Threads
1,136,339
Messages
5,675,195
Members
419,553
Latest member
hanahass

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
Top