<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Excel won't die! Task won't go away.... in VBA Forum</title>
    <link>https://forums.autodesk.com/t5/vba-forum/excel-won-t-die-task-won-t-go-away/m-p/1894508#M27198</link>
    <description>This problem has been around for a while.&lt;BR /&gt;
&lt;BR /&gt;
Try closing Excel (and removing references) in this order:&lt;BR /&gt;
1. Ranges&lt;BR /&gt;
2. Worksheets&lt;BR /&gt;
3. Workbooks&lt;BR /&gt;
4. Application&lt;BR /&gt;
&lt;BR /&gt;
This usually works, however I've seen where the rare case where it doesn't. Personally, if I am only reading data from Excel, I try to use ADO just to avoid this issue. If you have any experience opening a database, this may help.&lt;BR /&gt;
&lt;BR /&gt;
Set your connection details to:&lt;BR /&gt;
&lt;BR /&gt;
Provider=Microsoft.Jet.OLEDB.4.0;Data Source=FILENAME;Extended Properties="Excel 8.0;IMEX=1;HDR=NO"&lt;BR /&gt;
&lt;BR /&gt;
Where FILENAME is the full path to the excel file. You can then use the following SQL statement to pull all of Sheet1:&lt;BR /&gt;
&lt;BR /&gt;
"SELECT * FROM [Sheet1$]"&lt;BR /&gt;
&lt;BR /&gt;
You then simply read each row as a datarecord as if the worksheet it was a table in a database.&lt;BR /&gt;
&lt;BR /&gt;
It's a difficult concept get a handle on, but it is a way to read data from Excel without using COM interop (and therefore without running an excel application). I would give you some sample code, but it was written in VB.NET so it won't help you.&lt;BR /&gt;
&lt;BR /&gt;
Good luck.</description>
    <pubDate>Mon, 19 Feb 2007 19:01:02 GMT</pubDate>
    <dc:creator>jbooth</dc:creator>
    <dc:date>2007-02-19T19:01:02Z</dc:date>
    <item>
      <title>Excel won't die! Task won't go away....</title>
      <link>https://forums.autodesk.com/t5/vba-forum/excel-won-t-die-task-won-t-go-away/m-p/1894507#M27197</link>
      <description>Hi everyone, so I found a pretty nasty problem with my little code recently and I can't seem to get rid of it. I can't kill excel.exe out of my task manager until I close AutoCad.&lt;BR /&gt;
What am I doing wrong?&lt;BR /&gt;
 Here's the description of what I'm doing and if need be I can paste some code.&lt;BR /&gt;
&lt;BR /&gt;
I populate excel with data gathered from a bunch of drawings.&lt;BR /&gt;
&lt;BR /&gt;
1. Get the data into an array (thank Jeff), runs sweet.&lt;BR /&gt;
2. Create excel object if I can't getobject. (add reference to excel library)&lt;BR /&gt;
3. Open my spreadsheet&lt;BR /&gt;
4. Populate the cells.&lt;BR /&gt;
5. Quit, Nothing, and whatever else to excel in order for it to clear itself.&lt;BR /&gt;
&lt;BR /&gt;
This will still leave an instance of excel in task manager until AutoCad is closed.&lt;BR /&gt;
&lt;BR /&gt;
This causes a problem for second run of the same command. It is being very annoying to say the least.&lt;BR /&gt;
&lt;BR /&gt;
Anyone encountered this before?&lt;BR /&gt;
&lt;BR /&gt;
Thanks,&lt;BR /&gt;
Viktor.</description>
      <pubDate>Mon, 19 Feb 2007 17:57:54 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/excel-won-t-die-task-won-t-go-away/m-p/1894507#M27197</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2007-02-19T17:57:54Z</dc:date>
    </item>
    <item>
      <title>Re: Excel won't die! Task won't go away....</title>
      <link>https://forums.autodesk.com/t5/vba-forum/excel-won-t-die-task-won-t-go-away/m-p/1894508#M27198</link>
      <description>This problem has been around for a while.&lt;BR /&gt;
&lt;BR /&gt;
Try closing Excel (and removing references) in this order:&lt;BR /&gt;
1. Ranges&lt;BR /&gt;
2. Worksheets&lt;BR /&gt;
3. Workbooks&lt;BR /&gt;
4. Application&lt;BR /&gt;
&lt;BR /&gt;
This usually works, however I've seen where the rare case where it doesn't. Personally, if I am only reading data from Excel, I try to use ADO just to avoid this issue. If you have any experience opening a database, this may help.&lt;BR /&gt;
&lt;BR /&gt;
Set your connection details to:&lt;BR /&gt;
&lt;BR /&gt;
Provider=Microsoft.Jet.OLEDB.4.0;Data Source=FILENAME;Extended Properties="Excel 8.0;IMEX=1;HDR=NO"&lt;BR /&gt;
&lt;BR /&gt;
Where FILENAME is the full path to the excel file. You can then use the following SQL statement to pull all of Sheet1:&lt;BR /&gt;
&lt;BR /&gt;
"SELECT * FROM [Sheet1$]"&lt;BR /&gt;
&lt;BR /&gt;
You then simply read each row as a datarecord as if the worksheet it was a table in a database.&lt;BR /&gt;
&lt;BR /&gt;
It's a difficult concept get a handle on, but it is a way to read data from Excel without using COM interop (and therefore without running an excel application). I would give you some sample code, but it was written in VB.NET so it won't help you.&lt;BR /&gt;
&lt;BR /&gt;
Good luck.</description>
      <pubDate>Mon, 19 Feb 2007 19:01:02 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/excel-won-t-die-task-won-t-go-away/m-p/1894508#M27198</guid>
      <dc:creator>jbooth</dc:creator>
      <dc:date>2007-02-19T19:01:02Z</dc:date>
    </item>
    <item>
      <title>Re: Excel won't die! Task won't go away....</title>
      <link>https://forums.autodesk.com/t5/vba-forum/excel-won-t-die-task-won-t-go-away/m-p/1894509#M27199</link>
      <description>I think you're pointing directly at my problem, it seems that "ranges" is the pain I'm having.&lt;BR /&gt;
But to answer your second question, I am not just reading excel file, I populate and save it, i really don't want to close it, but since i was having problems killing it, i decided to at least save it and quit it, that wasn't helping.&lt;BR /&gt;
BUUUUUUUUUUT, I tested again with a much briefer code and it does kill it, so I was able to get down to this problem:&lt;BR /&gt;
&lt;BR /&gt;
I set do this&lt;BR /&gt;
dim row1 as range&lt;BR /&gt;
and it does work since I have it referenced, but i never set it to 0.&lt;BR /&gt;
Now how do you people get around doing what I have done? Do row1 needs to be a range, do I DIM it as object and then set it?&lt;BR /&gt;
Appreciate your help.&lt;BR /&gt;
Thanks,&lt;BR /&gt;
Viktor.</description>
      <pubDate>Mon, 19 Feb 2007 19:26:43 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/excel-won-t-die-task-won-t-go-away/m-p/1894509#M27199</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2007-02-19T19:26:43Z</dc:date>
    </item>
    <item>
      <title>Re: Excel won't die! Task won't go away....</title>
      <link>https://forums.autodesk.com/t5/vba-forum/excel-won-t-die-task-won-t-go-away/m-p/1894510#M27200</link>
      <description>Private Const WM_CLOSE = &amp;amp;H10&lt;BR /&gt;
[code]&lt;BR /&gt;
Function CloseXLS(objExcel As Excel.Application) As Boolean&lt;BR /&gt;
 Dim lngHwnd As Long&lt;BR /&gt;
    lngHwnd = FindWindow("XLMAIN", objExcel.Caption)&lt;BR /&gt;
    Set objExcel = Nothing&lt;BR /&gt;
    On Error Resume Next&lt;BR /&gt;
    SendMessage lngHwnd, WM_CLOSE, 0, 0&lt;BR /&gt;
    If Err = 0 Then CloseXLS = True&lt;BR /&gt;
    On Error GoTo 0&lt;BR /&gt;
End Function&lt;BR /&gt;
[/code]</description>
      <pubDate>Mon, 19 Feb 2007 21:35:08 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/excel-won-t-die-task-won-t-go-away/m-p/1894510#M27200</guid>
      <dc:creator>arcticad</dc:creator>
      <dc:date>2007-02-19T21:35:08Z</dc:date>
    </item>
    <item>
      <title>Re: Excel won't die! Task won't go away....</title>
      <link>https://forums.autodesk.com/t5/vba-forum/excel-won-t-die-task-won-t-go-away/m-p/1894511#M27201</link>
      <description>Thanks Articad,&lt;BR /&gt;
Could you give a little description on what is what? Like what is xlmain?</description>
      <pubDate>Mon, 19 Feb 2007 21:49:40 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/excel-won-t-die-task-won-t-go-away/m-p/1894511#M27201</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2007-02-19T21:49:40Z</dc:date>
    </item>
    <item>
      <title>Re: Excel won't die! Task won't go away....</title>
      <link>https://forums.autodesk.com/t5/vba-forum/excel-won-t-die-task-won-t-go-away/m-p/1894512#M27202</link>
      <description>XLMAIN is just the name given to excel.&lt;BR /&gt;
You won't be given a prompt to save this simply kills the running process for excel. &lt;BR /&gt;
&lt;BR /&gt;
Be Sure and remove all the references as mentioned above. &lt;BR /&gt;
&lt;BR /&gt;
You also need this at the top of your module. &lt;BR /&gt;
&lt;BR /&gt;
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Private Const WM_CLOSE = &amp;amp;H10&lt;BR /&gt;
&lt;BR /&gt;
Function CloseXLS(objExcel As Excel.Application) As Boolean&lt;BR /&gt;
 Dim lngHwnd As Long&lt;BR /&gt;
    lngHwnd = FindWindow("XLMAIN", objExcel.Caption) ' Get The ID of the Window of the Running Process&lt;BR /&gt;
    Set objExcel = Nothing&lt;BR /&gt;
    On Error Resume Next&lt;BR /&gt;
    SendMessage lngHwnd, WM_CLOSE, 0, 0 ' Tell the Windows API to kill the process&lt;BR /&gt;
    If Err = 0 Then CloseXLS = True&lt;BR /&gt;
    On Error GoTo 0&lt;BR /&gt;
End Function</description>
      <pubDate>Mon, 19 Feb 2007 23:31:34 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/excel-won-t-die-task-won-t-go-away/m-p/1894512#M27202</guid>
      <dc:creator>arcticad</dc:creator>
      <dc:date>2007-02-19T23:31:34Z</dc:date>
    </item>
    <item>
      <title>Re: Excel won't die! Task won't go away....</title>
      <link>https://forums.autodesk.com/t5/vba-forum/excel-won-t-die-task-won-t-go-away/m-p/1894513#M27203</link>
      <description>The way I've gotten around this is to never set a Variable to a Range &lt;BR /&gt;
Object. Access it through the Worksheet Object. Since I've been using code &lt;BR /&gt;
like the following example, I have not seen that problem.&lt;BR /&gt;
&lt;BR /&gt;
''Portions of the following code adapted from code posted by Randall Rath&lt;BR /&gt;
Option Explicit&lt;BR /&gt;
&lt;BR /&gt;
Function IsExcelRunning() As Boolean&lt;BR /&gt;
     Dim objXL As Excel.Application&lt;BR /&gt;
     On Error Resume Next&lt;BR /&gt;
     Set objXL = GetObject(, "Excel.Application")&lt;BR /&gt;
     IsExcelRunning = (Err.Number = 0)&lt;BR /&gt;
     Set objXL = Nothing&lt;BR /&gt;
     Err.Clear&lt;BR /&gt;
   End Function&lt;BR /&gt;
&lt;BR /&gt;
Public Sub AddData(DwgFullName As String, vData As Variant)&lt;BR /&gt;
Dim sXlFilNam As String&lt;BR /&gt;
&lt;BR /&gt;
  sXlFilNam = Left(DwgFullName, Len(DwgFullName) - 3) &amp;amp; "xls"&lt;BR /&gt;
  Dim oXL As Excel.Application&lt;BR /&gt;
  Dim oWb As Excel.Workbook&lt;BR /&gt;
  Dim oWs As Excel.Worksheet&lt;BR /&gt;
  Dim blnXLRunning As Boolean&lt;BR /&gt;
     blnXLRunning = IsExcelRunning()&lt;BR /&gt;
     If blnXLRunning Then&lt;BR /&gt;
       Set oXL = GetObject(, "Excel.Application")&lt;BR /&gt;
     Else&lt;BR /&gt;
       Set oXL = CreateObject("Excel.Application")&lt;BR /&gt;
       oXL.Visible = False&lt;BR /&gt;
       oXL.UserControl = False&lt;BR /&gt;
     End If&lt;BR /&gt;
  On Error Resume Next&lt;BR /&gt;
  oXL.Visible = True&lt;BR /&gt;
  Set oWb = oXL.Workbooks.Open(sXlFilNam)&lt;BR /&gt;
  If oWb Is Nothing Then&lt;BR /&gt;
    Set oWb = oXL.Workbooks.Add&lt;BR /&gt;
    oWb.SaveAs (sXlFilNam)&lt;BR /&gt;
  End If&lt;BR /&gt;
&lt;BR /&gt;
  Set oWs = oWb.Worksheets(1)&lt;BR /&gt;
  On Error GoTo 0&lt;BR /&gt;
  oWs.Range("A1:D4").Name = "TEST"&lt;BR /&gt;
  oWs.Range("TEST").ClearContents 'to ensure named range is clear of &lt;BR /&gt;
previous data&lt;BR /&gt;
  oWs.Range("TEST").Resize(UBound(vData, 1), UBound(vData, 2)).Value = vData&lt;BR /&gt;
exithere:&lt;BR /&gt;
  Set oWs = Nothing&lt;BR /&gt;
&lt;BR /&gt;
  oWb.Save: oWb.Close&lt;BR /&gt;
  Set oWb = Nothing&lt;BR /&gt;
&lt;BR /&gt;
  oXL.Quit&lt;BR /&gt;
  Set oXL = Nothing&lt;BR /&gt;
&lt;BR /&gt;
End Sub&lt;BR /&gt;
&lt;BR /&gt;
Sub testmenow()&lt;BR /&gt;
Dim tr(4, 4) As Double&lt;BR /&gt;
&lt;BR /&gt;
AddData ThisDrawing.FullName, tr&lt;BR /&gt;
&lt;BR /&gt;
End Sub&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;VIK07&gt; wrote in message news:5491919@discussion.autodesk.com...&lt;BR /&gt;
I think you're pointing directly at my problem, it seems that "ranges" is &lt;BR /&gt;
the pain I'm having.&lt;BR /&gt;
But to answer your second question, I am not just reading excel file, I &lt;BR /&gt;
populate and save it, i really don't want to close it, but since i was &lt;BR /&gt;
having problems killing it, i decided to at least save it and quit it, that &lt;BR /&gt;
wasn't helping.&lt;BR /&gt;
BUUUUUUUUUUT, I tested again with a much briefer code and it does kill it, &lt;BR /&gt;
so I was able to get down to this problem:&lt;BR /&gt;
&lt;BR /&gt;
I set do this&lt;BR /&gt;
dim row1 as range&lt;BR /&gt;
and it does work since I have it referenced, but i never set it to 0.&lt;BR /&gt;
Now how do you people get around doing what I have done? Do row1 needs to be &lt;BR /&gt;
a range, do I DIM it as object and then set it?&lt;BR /&gt;
Appreciate your help.&lt;BR /&gt;
Thanks,&lt;BR /&gt;
Viktor.&lt;/VIK07&gt;</description>
      <pubDate>Tue, 20 Feb 2007 00:29:22 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/excel-won-t-die-task-won-t-go-away/m-p/1894513#M27203</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2007-02-20T00:29:22Z</dc:date>
    </item>
    <item>
      <title>Re: Excel won't die! Task won't go away....</title>
      <link>https://forums.autodesk.com/t5/vba-forum/excel-won-t-die-task-won-t-go-away/m-p/1894514#M27204</link>
      <description>Here's where my problem was, I think all of you were sort of pointing in the right direction, I was just ignoring the problem though.&lt;BR /&gt;
&lt;BR /&gt;
Sub TestExcel()&lt;BR /&gt;
Dim xl As Excel.Application&lt;BR /&gt;
Dim wb As Excel.Workbook&lt;BR /&gt;
Dim ws As Excel.Worksheet&lt;BR /&gt;
Dim row(0 To 3) As Excel.Range&lt;BR /&gt;
 &lt;BR /&gt;
Set xl = CreateObject("Excel.Application")&lt;BR /&gt;
xl.Visible = True&lt;BR /&gt;
Set wb = xl.Workbooks.Open(FileName:="J:\Shared Data\AutoCad Support\Forms\Transmittal\transmittal-2007.xls")&lt;BR /&gt;
Set ws = wb.Worksheets("transmittal")&lt;BR /&gt;
'---------------problem area---------------------'&lt;BR /&gt;
ws.Range("b19").Select&lt;BR /&gt;
Set row(0) = xl.ActiveCell&lt;BR /&gt;
xl.ActiveCell.Offset(0, 2).Select&lt;BR /&gt;
Set row(1) = xl.ActiveCell&lt;BR /&gt;
xl.ActiveCell.Offset(0, 1).Select&lt;BR /&gt;
Set row(2) = xl.ActiveCell&lt;BR /&gt;
xl.ActiveCell.Offset(0, 3).Select&lt;BR /&gt;
Set row(3) = xl.ActiveCell&lt;BR /&gt;
row(0).Value = "test1"&lt;BR /&gt;
row(1).Value = "test2"&lt;BR /&gt;
row(2).Value = "test3"&lt;BR /&gt;
row(3).Value = "test4"&lt;BR /&gt;
'---------------problem area---------------------'&lt;BR /&gt;
wb.SaveAs FileName:="C:\test"&lt;BR /&gt;
wb.Close False&lt;BR /&gt;
xl.Quit&lt;BR /&gt;
 &lt;BR /&gt;
Set row(0) = Nothing&lt;BR /&gt;
Set row(1) = Nothing&lt;BR /&gt;
Set row(2) = Nothing&lt;BR /&gt;
Set row(3) = Nothing&lt;BR /&gt;
Set ws = Nothing&lt;BR /&gt;
Set wb = Nothing&lt;BR /&gt;
Set xl = Nothing&lt;BR /&gt;
End Sub&lt;BR /&gt;
&lt;BR /&gt;
This works good, and the reason why it wasn't working good is because I was trying to use Activecell out of a worksheet, not out of XL.Activecell, it made no sense at the time for me to try it so I looked for some other answer, but that is really the bogger. Hope this helps someone else in the future.&lt;BR /&gt;
Thanks to all for your help.&lt;BR /&gt;
Viktor.</description>
      <pubDate>Tue, 20 Feb 2007 18:34:05 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/excel-won-t-die-task-won-t-go-away/m-p/1894514#M27204</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2007-02-20T18:34:05Z</dc:date>
    </item>
    <item>
      <title>Re: Excel won't die! Task won't go away....</title>
      <link>https://forums.autodesk.com/t5/vba-forum/excel-won-t-die-task-won-t-go-away/m-p/1894515#M27205</link>
      <description>Killing the Excel process will only annoy users that run multiple instances of Excel, as you have no idea at runtime which instance of Excel you will get when using FindWindow().&lt;BR /&gt;
&lt;BR /&gt;
You could hack it by changing the name of the window, but disposing of references as you use them is a better programming practice.&lt;BR /&gt;
&lt;BR /&gt;
I'm not sure if this works, but try something similar to the following:&lt;BR /&gt;
&lt;BR /&gt;
With sheet.Range("A1:B5")&lt;BR /&gt;
...Do stuff with A1-B5...&lt;BR /&gt;
End With&lt;BR /&gt;
&lt;BR /&gt;
That MAY make sure the VB engine doesn't keep references to excel objects after you are finished with them.</description>
      <pubDate>Wed, 21 Feb 2007 00:04:44 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/excel-won-t-die-task-won-t-go-away/m-p/1894515#M27205</guid>
      <dc:creator>jbooth</dc:creator>
      <dc:date>2007-02-21T00:04:44Z</dc:date>
    </item>
  </channel>
</rss>

