 




<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: VB6 cannot shutdown Excel.exe except by ending VB program</title>
	<atom:link href="http://itknowledgeexchange.techtarget.com/itanswers/vb6-cannot-shutdown-excelexe-except-by-ending-vb-program/feed/" rel="self" type="application/rss+xml" />
	<link>http://itknowledgeexchange.techtarget.com/itanswers/vb6-cannot-shutdown-excelexe-except-by-ending-vb-program/</link>
	<description></description>
	<lastBuildDate>Sun, 19 May 2013 03:14:28 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
	<item>
		<title>By: lopezw</title>
		<link>http://itknowledgeexchange.techtarget.com/itanswers/vb6-cannot-shutdown-excelexe-except-by-ending-vb-program/#comment-36578</link>
		<dc:creator>lopezw</dc:creator>
		<pubDate>Wed, 25 Jan 2006 09:34:44 +0000</pubDate>
		<guid isPermaLink="false">#comment-36578</guid>
		<description><![CDATA[I can now successfully close Excel form within VB but I have to remove all uses of With..End With, Activesheet, Activecell, &amp; Range().Select.  Apparently, using any one of these invokes Excel &amp; cannot be closed from inside VB.
These can be replaced with direct references; this done then all instances of &quot;..Activate&quot; are unnecessary. 

Excel is closed within VB after removing the above items &amp; replacing DataIn(nrow, ncol) = .Offset(nrow - 1, ncol - 1).Value with DataIn(nrow, ncol) = DataSheet.Range(&quot;A2&quot;).Offset(nrow - 1, ncol - 1).Value.  

Note that if a range name is needed as a reference, then the following lines will work:
Dim DataRange as Range
Dim DataCell As String
DataCell = DataSheet.Range(&quot;DataRange&quot;).Item(1, 1).Address
DataIn(nrow, ncol) = DataSheet.Range(DataCell).Offset(nrow - 1, ncol - 1).Value
 ]]></description>
		<content:encoded><![CDATA[<p>I can now successfully close Excel form within VB but I have to remove all uses of With..End With, Activesheet, Activecell, &amp; Range().Select.  Apparently, using any one of these invokes Excel &amp; cannot be closed from inside VB.<br />
These can be replaced with direct references; this done then all instances of &#8220;..Activate&#8221; are unnecessary. </p>
<p>Excel is closed within VB after removing the above items &amp; replacing DataIn(nrow, ncol) = .Offset(nrow &#8211; 1, ncol &#8211; 1).Value with DataIn(nrow, ncol) = DataSheet.Range(&#8220;A2&#8243;).Offset(nrow &#8211; 1, ncol &#8211; 1).Value.  </p>
<p>Note that if a range name is needed as a reference, then the following lines will work:<br />
Dim DataRange as Range<br />
Dim DataCell As String<br />
DataCell = DataSheet.Range(&#8220;DataRange&#8221;).Item(1, 1).Address<br />
DataIn(nrow, ncol) = DataSheet.Range(DataCell).Offset(nrow &#8211; 1, ncol &#8211; 1).Value</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: skmehab</title>
		<link>http://itknowledgeexchange.techtarget.com/itanswers/vb6-cannot-shutdown-excelexe-except-by-ending-vb-program/#comment-36579</link>
		<dc:creator>skmehab</dc:creator>
		<pubDate>Wed, 25 Jan 2006 07:36:50 +0000</pubDate>
		<guid isPermaLink="false">#comment-36579</guid>
		<description><![CDATA[Hi,

I think that adding one more line will solve this problem. After creating object of Excel Appliction, you either create new workbook or open an existing one. After this step add this line...

xlapp.UserControl = True  &#039; xlall is the object of ms excel

Thanks &amp; Regards]]></description>
		<content:encoded><![CDATA[<p>Hi,</p>
<p>I think that adding one more line will solve this problem. After creating object of Excel Appliction, you either create new workbook or open an existing one. After this step add this line&#8230;</p>
<p>xlapp.UserControl = True  &#8216; xlall is the object of ms excel</p>
<p>Thanks &amp; Regards</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: charlesjc</title>
		<link>http://itknowledgeexchange.techtarget.com/itanswers/vb6-cannot-shutdown-excelexe-except-by-ending-vb-program/#comment-36580</link>
		<dc:creator>charlesjc</dc:creator>
		<pubDate>Tue, 24 Jan 2006 16:54:27 +0000</pubDate>
		<guid isPermaLink="false">#comment-36580</guid>
		<description><![CDATA[Copy this into a new project and call the method from a command button:

Option Explicit
Option Base 1 &#039; to set matrix origin to (1,1)

Sub Run_test()
    Dim ExcelObj As Excel.Application
    Dim DataFile As Excel.Workbook
    Dim DataSheet As Excel.Worksheet
    Dim DataInFileName As String
    Dim DataOutFileName As String
    Dim DataOutTemplateName As String
    Dim DataIn(9, 9) As Single
    Dim DataOut(9, 9) As Single
    Dim ncol As Integer
    Dim nrow As Integer
    Dim Current_Date As Variant
    Dim Current_Time As Variant
    Dim Current_Date_Full As Variant
    
    Current_Date = Date
    Current_Date = Replace(Current_Date, &quot;/&quot;, &quot;_&quot;)
    Current_Time = Time
    Current_Time = Replace(Current_Time, &quot;:&quot;, &quot;-&quot;)
    Current_Date_Full = Current_Date &amp; &quot;_&quot; &amp; Current_Time
    
    DataInFileName = &quot;C:DataIn.xls&quot;
    DataOutTemplateName = &quot;C:DataOutTemplate.xls&quot;
    DataOutFileName = &quot;C:DataOut_&quot; &amp; Current_Date_Full &amp; &quot;.xls&quot;
    
    &#039;Opening/reading/closing Excel input data file
    
    &#039;Set ExcelObj = Excel.Application       &#039;Yours
    Set ExcelObj = New Excel.Application    &#039;Mine
    
    ExcelObj.Visible = False &#039;not visible even without this line
    
    Set DataFile = ExcelObj.Workbooks.Open(DataInFileName)
    DataFile.Activate
    Set DataSheet = DataFile.Worksheets(&quot;Input Data&quot;)
    DataSheet.Activate
    
    MsgBox &quot;Excel is open&quot;
&#039;    With ActiveSheet
&#039;        Range(&quot;A2&quot;).Select
&#039;        With ActiveCell
&#039;            For nrow = 1 To 9
&#039;                For ncol = 1 To 9
&#039;                    DataIn(nrow, ncol) = .Offset(nrow - 1, ncol - 1).Value
&#039;                Next ncol
&#039;            Next nrow
&#039;        End With &#039;for activecell
&#039;    End With &#039;for activesheet
    
    &#039;Closing Excel Input Data File without saving
    Set DataSheet = Nothing
    DataFile.Close (False)
    Set DataFile = Nothing
    ExcelObj.Quit
    Set ExcelObj = Nothing
    
    MsgBox &quot;Excel is now closed.&quot;
    
&#039;    &#039;generating output data
&#039;    For nrow = 1 To 9
&#039;        For ncol = 1 To 9
&#039;            DataOut(nrow, ncol) = 0.001 * DataIn(nrow, ncol)
&#039;        Next ncol
&#039;    Next nrow
    
    &#039;Opening/writing/saving Excel output data file
    &#039;Set ExcelObj = Excel.Application       &#039;Yours
    Set ExcelObj = New Excel.Application    &#039;Mine
    
    ExcelObj.Visible = False &#039;not visible even without this line
    Set DataFile = ExcelObj.Workbooks.Open(DataOutTemplateName)
    DataFile.Activate
    Set DataSheet = DataFile.Worksheets(&quot;Output Data&quot;)
    DataSheet.Activate
    
    MsgBox &quot;Excel is open again&quot;
    
&#039;    With ActiveSheet
&#039;        Range(&quot;A2&quot;).Select
&#039;        With ActiveCell
&#039;            For nrow = 1 To 9
&#039;                For ncol = 1 To 9
&#039;                    .Offset(nrow - 1, ncol - 1).Value = DataOut(nrow, ncol)
&#039;                Next ncol
&#039;            Next nrow
&#039;        End With &#039;for activecell
&#039;    End With &#039;for activesheet
&#039;
&#039;    &#039;Saving &amp; Closing Excel Output Data File
&#039;    DataFile.SaveAs (DataOutFileName)
    Set DataSheet = Nothing
    DataFile.Close (False)
    Set DataFile = Nothing
    
    ExcelObj.Quit
    Set ExcelObj = Nothing
    
    MsgBox (&quot;Check Task Manager to see that the Excel.exe process is still active&quot;)
    
End Sub

Private Sub Command1_Click()
    Call Run_test
End Sub
]]></description>
		<content:encoded><![CDATA[<p>Copy this into a new project and call the method from a command button:</p>
<p>Option Explicit<br />
Option Base 1 &#8216; to set matrix origin to (1,1)</p>
<p>Sub Run_test()<br />
    Dim ExcelObj As Excel.Application<br />
    Dim DataFile As Excel.Workbook<br />
    Dim DataSheet As Excel.Worksheet<br />
    Dim DataInFileName As String<br />
    Dim DataOutFileName As String<br />
    Dim DataOutTemplateName As String<br />
    Dim DataIn(9, 9) As Single<br />
    Dim DataOut(9, 9) As Single<br />
    Dim ncol As Integer<br />
    Dim nrow As Integer<br />
    Dim Current_Date As Variant<br />
    Dim Current_Time As Variant<br />
    Dim Current_Date_Full As Variant</p>
<p>    Current_Date = Date<br />
    Current_Date = Replace(Current_Date, &#8220;/&#8221;, &#8220;_&#8221;)<br />
    Current_Time = Time<br />
    Current_Time = Replace(Current_Time, &#8220;:&#8221;, &#8220;-&#8221;)<br />
    Current_Date_Full = Current_Date &amp; &#8220;_&#8221; &amp; Current_Time</p>
<p>    DataInFileName = &#8220;C:DataIn.xls&#8221;<br />
    DataOutTemplateName = &#8220;C:DataOutTemplate.xls&#8221;<br />
    DataOutFileName = &#8220;C:DataOut_&#8221; &amp; Current_Date_Full &amp; &#8220;.xls&#8221;</p>
<p>    &#8216;Opening/reading/closing Excel input data file</p>
<p>    &#8216;Set ExcelObj = Excel.Application       &#8216;Yours<br />
    Set ExcelObj = New Excel.Application    &#8216;Mine</p>
<p>    ExcelObj.Visible = False &#8216;not visible even without this line</p>
<p>    Set DataFile = ExcelObj.Workbooks.Open(DataInFileName)<br />
    DataFile.Activate<br />
    Set DataSheet = DataFile.Worksheets(&#8220;Input Data&#8221;)<br />
    DataSheet.Activate</p>
<p>    MsgBox &#8220;Excel is open&#8221;<br />
&#8216;    With ActiveSheet<br />
&#8216;        Range(&#8220;A2&#8243;).Select<br />
&#8216;        With ActiveCell<br />
&#8216;            For nrow = 1 To 9<br />
&#8216;                For ncol = 1 To 9<br />
&#8216;                    DataIn(nrow, ncol) = .Offset(nrow &#8211; 1, ncol &#8211; 1).Value<br />
&#8216;                Next ncol<br />
&#8216;            Next nrow<br />
&#8216;        End With &#8216;for activecell<br />
&#8216;    End With &#8216;for activesheet</p>
<p>    &#8216;Closing Excel Input Data File without saving<br />
    Set DataSheet = Nothing<br />
    DataFile.Close (False)<br />
    Set DataFile = Nothing<br />
    ExcelObj.Quit<br />
    Set ExcelObj = Nothing</p>
<p>    MsgBox &#8220;Excel is now closed.&#8221;</p>
<p>&#8216;    &#8216;generating output data<br />
&#8216;    For nrow = 1 To 9<br />
&#8216;        For ncol = 1 To 9<br />
&#8216;            DataOut(nrow, ncol) = 0.001 * DataIn(nrow, ncol)<br />
&#8216;        Next ncol<br />
&#8216;    Next nrow</p>
<p>    &#8216;Opening/writing/saving Excel output data file<br />
    &#8216;Set ExcelObj = Excel.Application       &#8216;Yours<br />
    Set ExcelObj = New Excel.Application    &#8216;Mine</p>
<p>    ExcelObj.Visible = False &#8216;not visible even without this line<br />
    Set DataFile = ExcelObj.Workbooks.Open(DataOutTemplateName)<br />
    DataFile.Activate<br />
    Set DataSheet = DataFile.Worksheets(&#8220;Output Data&#8221;)<br />
    DataSheet.Activate</p>
<p>    MsgBox &#8220;Excel is open again&#8221;</p>
<p>&#8216;    With ActiveSheet<br />
&#8216;        Range(&#8220;A2&#8243;).Select<br />
&#8216;        With ActiveCell<br />
&#8216;            For nrow = 1 To 9<br />
&#8216;                For ncol = 1 To 9<br />
&#8216;                    .Offset(nrow &#8211; 1, ncol &#8211; 1).Value = DataOut(nrow, ncol)<br />
&#8216;                Next ncol<br />
&#8216;            Next nrow<br />
&#8216;        End With &#8216;for activecell<br />
&#8216;    End With &#8216;for activesheet<br />
&#8216;<br />
&#8216;    &#8216;Saving &amp; Closing Excel Output Data File<br />
&#8216;    DataFile.SaveAs (DataOutFileName)<br />
    Set DataSheet = Nothing<br />
    DataFile.Close (False)<br />
    Set DataFile = Nothing</p>
<p>    ExcelObj.Quit<br />
    Set ExcelObj = Nothing</p>
<p>    MsgBox (&#8220;Check Task Manager to see that the Excel.exe process is still active&#8221;)</p>
<p>End Sub</p>
<p>Private Sub Command1_Click()<br />
    Call Run_test<br />
End Sub</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: daveinaz</title>
		<link>http://itknowledgeexchange.techtarget.com/itanswers/vb6-cannot-shutdown-excelexe-except-by-ending-vb-program/#comment-36581</link>
		<dc:creator>daveinaz</dc:creator>
		<pubDate>Mon, 23 Jan 2006 11:30:34 +0000</pubDate>
		<guid isPermaLink="false">#comment-36581</guid>
		<description><![CDATA[Charles is correct, up to a point. That is better syntax, but there may be more to it than that. If that doesn&#039;t resolve the issue, see MS KB article 178510 (http://support.microsoft.com/kb/178510/en-us), entitled &quot;Excel automation fails second time code runs&quot;. You wouldn&#039;t be getting that error, because you&#039;re not successfully closing Excel, but the cause is the same; an unreleased reference to one of the Excel objects. (Run your code, terminate the process in Task Manager, and run the code, again. I bet you get one of the errors listed in the article.) In your case, it looks like it might be the Activesheet or Activecell reference, but I may be overlooking something. ]]></description>
		<content:encoded><![CDATA[<p>Charles is correct, up to a point. That is better syntax, but there may be more to it than that. If that doesn&#8217;t resolve the issue, see MS KB article 178510 (<a href="http://support.microsoft.com/kb/178510/en-us" rel="nofollow">http://support.microsoft.com/kb/178510/en-us</a>), entitled &#8220;Excel automation fails second time code runs&#8221;. You wouldn&#8217;t be getting that error, because you&#8217;re not successfully closing Excel, but the cause is the same; an unreleased reference to one of the Excel objects. (Run your code, terminate the process in Task Manager, and run the code, again. I bet you get one of the errors listed in the article.) In your case, it looks like it might be the Activesheet or Activecell reference, but I may be overlooking something. </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: lopezw</title>
		<link>http://itknowledgeexchange.techtarget.com/itanswers/vb6-cannot-shutdown-excelexe-except-by-ending-vb-program/#comment-36582</link>
		<dc:creator>lopezw</dc:creator>
		<pubDate>Mon, 23 Jan 2006 09:53:26 +0000</pubDate>
		<guid isPermaLink="false">#comment-36582</guid>
		<description><![CDATA[Replacing the Set ExcelObj = Excel.Application with Set ExcelObj = New Excel.Application causes the application to bomb.  Setting the 2nd occurrence only to New is OK but Excel is stll active until the VB executable is terminated.

I also tried setting 1st occurrence to Set ExcelObj = New Excel.Application &amp; deleting the 1st occurence of ExcelObj.quit &amp; Set ExcelObj = Nothing, along with deleting the 2nd Set ExcelObj = New Excel.Application, ExcelObj.Visible.  Excel is stll active until the VB executable is terminated.  (Note that Setting ExcelObj = Excel.Application had the same effects.)


]]></description>
		<content:encoded><![CDATA[<p>Replacing the Set ExcelObj = Excel.Application with Set ExcelObj = New Excel.Application causes the application to bomb.  Setting the 2nd occurrence only to New is OK but Excel is stll active until the VB executable is terminated.</p>
<p>I also tried setting 1st occurrence to Set ExcelObj = New Excel.Application &amp; deleting the 1st occurence of ExcelObj.quit &amp; Set ExcelObj = Nothing, along with deleting the 2nd Set ExcelObj = New Excel.Application, ExcelObj.Visible.  Excel is stll active until the VB executable is terminated.  (Note that Setting ExcelObj = Excel.Application had the same effects.)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: bappib</title>
		<link>http://itknowledgeexchange.techtarget.com/itanswers/vb6-cannot-shutdown-excelexe-except-by-ending-vb-program/#comment-36583</link>
		<dc:creator>bappib</dc:creator>
		<pubDate>Mon, 23 Jan 2006 05:57:10 +0000</pubDate>
		<guid isPermaLink="false">#comment-36583</guid>
		<description><![CDATA[Quit the Excel Application and then destroy this object

ExcelObj.Application.Quit
Set ExcelObj = Nothing]]></description>
		<content:encoded><![CDATA[<p>Quit the Excel Application and then destroy this object</p>
<p>ExcelObj.Application.Quit<br />
Set ExcelObj = Nothing</p>
]]></content:encoded>
	</item>
</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Page Caching using memcached
Database Caching 6/8 queries in 0.010 seconds using memcached
Object Caching 339/340 objects using memcached

Served from: itknowledgeexchange.techtarget.com @ 2013-05-19 17:07:38 -->