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
 

Forum statistics

Threads
1,082,018
Messages
5,362,702
Members
400,686
Latest member
Aakash

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top