<?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: How to end Excel from VBA in VBA Forum</title>
    <link>https://forums.autodesk.com/t5/vba-forum/how-to-end-excel-from-vba/m-p/304816#M64010</link>
    <description>Hi,&lt;BR /&gt;
I have to tryed to rewrite this code on pure VBA with using&lt;BR /&gt;
of API functions see my example&lt;BR /&gt;
Make sure that in VBEditor -&amp;gt;Tools-&amp;gt;Options-&amp;gt;General&lt;BR /&gt;
was checked "Break on Unhandled Errors" button&lt;BR /&gt;
Feel free to adapt it to your suit&lt;BR /&gt;
&lt;BR /&gt;
Option Explicit&lt;BR /&gt;
     Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)&lt;BR /&gt;
     Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long&lt;BR /&gt;
     Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Integer, ByVal lParam As Any) As Long&lt;BR /&gt;
     Const WT_SLEEP = 2500&lt;BR /&gt;
     Const WM_CLOSE = &amp;amp;H10&lt;BR /&gt;
     Const WM_ACTIVATEAPP = &amp;amp;H1C&lt;BR /&gt;
     Const WM_USER = 1024&lt;BR /&gt;
     Const gcClassnameMSExcel = "XLMAIN"&lt;BR /&gt;
&lt;BR /&gt;
Sub TestExcelQuit()&lt;BR /&gt;
Dim xlApp As Object&lt;BR /&gt;
Dim xlBook As Object&lt;BR /&gt;
Dim xlSheet As Object&lt;BR /&gt;
Dim hwnd As Long&lt;BR /&gt;
Dim WhatD As Long&lt;BR /&gt;
On Error Resume Next&lt;BR /&gt;
Set xlApp = Nothing&lt;BR /&gt;
Set xlApp = GetObject(, "Excel.Application")&lt;BR /&gt;
If Err.Number  0 Then 'read this line as If Err.Number not equal zero&lt;BR /&gt;
'because this symbol not shown correctly in this code&lt;BR /&gt;
'I don't know why&lt;BR /&gt;
Set xlApp = CreateObject("Excel.Application")&lt;BR /&gt;
End If&lt;BR /&gt;
Err.Clear&lt;BR /&gt;
On Error GoTo Err_Control&lt;BR /&gt;
MsgBox "Sleep 2.5 seconds"&lt;BR /&gt;
Set xlBook = xlApp.Workbooks.Add&lt;BR /&gt;
Set xlSheet = xlBook.worksheets(1)&lt;BR /&gt;
xlSheet.Application.Visible = True&lt;BR /&gt;
&lt;BR /&gt;
Sleep WT_SLEEP ' pause 2.5 sec&lt;BR /&gt;
&lt;BR /&gt;
xlBook.Close Savechanges:=False&lt;BR /&gt;
Set xlSheet = Nothing&lt;BR /&gt;
Set xlBook = Nothing&lt;BR /&gt;
&lt;BR /&gt;
     hwnd = FindWindow(gcClassnameMSExcel, 0)&lt;BR /&gt;
&lt;BR /&gt;
     Do While hwnd &amp;gt; 0&lt;BR /&gt;
          'WhatD = SendMessage(hwnd, WM_USER + 18, 0, ByVal 0&amp;amp;)    ' Microsoft Excel 95&lt;BR /&gt;
          WhatD = SendMessage(hwnd, WM_ACTIVATEAPP, 0, ByVal 0&amp;amp;)   ' Microsoft Office 2000 or Microsoft Office XP&lt;BR /&gt;
          'Set xlApp = GetObject(, "Excel.Application")&lt;BR /&gt;
          xlApp.Quit&lt;BR /&gt;
          hwnd = FindWindow(gcClassnameMSExcel, 0)&lt;BR /&gt;
&lt;BR /&gt;
     Loop&lt;BR /&gt;
Set xlApp = Nothing&lt;BR /&gt;
&lt;BR /&gt;
Err_Control:&lt;BR /&gt;
If Err Then&lt;BR /&gt;
MsgBox Err.Description&lt;BR /&gt;
Set xlSheet = Nothing&lt;BR /&gt;
Set xlBook = Nothing&lt;BR /&gt;
Set xlApp = Nothing&lt;BR /&gt;
End If&lt;BR /&gt;
&lt;BR /&gt;
End Sub&lt;BR /&gt;
&lt;BR /&gt;
Fatty&lt;BR /&gt;
&lt;BR /&gt;
~'J'~

Message was edited by: Fatty</description>
    <pubDate>Mon, 27 Nov 2006 12:44:49 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2006-11-27T12:44:49Z</dc:date>
    <item>
      <title>How to end Excel from VBA</title>
      <link>https://forums.autodesk.com/t5/vba-forum/how-to-end-excel-from-vba/m-p/304809#M64003</link>
      <description>I'm having a hell of time trying to close down excel from my vba program.&lt;BR /&gt;
My operating system is Windows 98.&lt;BR /&gt;
&lt;BR /&gt;
Here is the code:&lt;BR /&gt;
&lt;BR /&gt;
Private Sub Excel_Running_Check()&lt;BR /&gt;
Dim excelApp As Excel.Application&lt;BR /&gt;
On Error Resume Next&lt;BR /&gt;
  Err.Clear&lt;BR /&gt;
  Set excelApp = GetObject(, "excel.application")&lt;BR /&gt;
  If Err &amp;lt;&amp;gt; 0 Then&lt;BR /&gt;
    Err.Clear&lt;BR /&gt;
  Else&lt;BR /&gt;
    excelApp.DisplayAlerts = False&lt;BR /&gt;
    excelApp.ActiveWorkbook.Close&lt;BR /&gt;
    excelApp.Quit&lt;BR /&gt;
    Set excelApp = Nothing&lt;BR /&gt;
End Sub&lt;BR /&gt;
&lt;BR /&gt;
The idea for this sub is to check for a running instance of excel.  If it&lt;BR /&gt;
exists then close it down before opening up another instance of excel.  The&lt;BR /&gt;
problem is that excel still remains memory resident.  I verify this by using&lt;BR /&gt;
ctrl-alt-del to open the task manager and notice that excel is still&lt;BR /&gt;
running.   The only way I can get excel to stop running is to close down my&lt;BR /&gt;
application with the End function.  I've seen similar posts all over the&lt;BR /&gt;
internet but I haven't found an answer to it yet.  The fact that excel is&lt;BR /&gt;
not released from memory causes problems when reopening excel through my&lt;BR /&gt;
program.  Subsequent intances of spreadsheets are not formatted&lt;BR /&gt;
programatically as is intended through my code.  Several instances of excel&lt;BR /&gt;
remain running in task manager.  Please help.</description>
      <pubDate>Tue, 29 Apr 2003 07:49:42 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/how-to-end-excel-from-vba/m-p/304809#M64003</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2003-04-29T07:49:42Z</dc:date>
    </item>
    <item>
      <title>Re: How to end Excel from VBA</title>
      <link>https://forums.autodesk.com/t5/vba-forum/how-to-end-excel-from-vba/m-p/304810#M64004</link>
      <description>This is a known problem with Excel. I suspect that you havn't shown all of&lt;BR /&gt;
your code, but the rule here is to clear up all your object variables in the&lt;BR /&gt;
reverse of the hierarchical order that you derived them. For example, you&lt;BR /&gt;
start with an application object, then use it to create a workbook object,&lt;BR /&gt;
and then use that object to create a sheet object. Before you close the app,&lt;BR /&gt;
you need to set to nothing, first the sheet object and then the workbook&lt;BR /&gt;
object. Then you can deal with the app object.&lt;BR /&gt;
&lt;BR /&gt;
--&lt;BR /&gt;
Ed&lt;BR /&gt;
--&lt;BR /&gt;
&lt;BR /&gt;
"Gordon Reichhardt" &lt;REICHHARDTG&gt; wrote in message&lt;BR /&gt;
news:66D7FF33CB39611744607A55E9E7CD31@in.WebX.maYIadrTaRb...&lt;BR /&gt;
&amp;gt; I'm having a hell of time trying to close down excel from my vba program.&lt;BR /&gt;
&amp;gt; My operating system is Windows 98.&lt;BR /&gt;
&amp;gt;&lt;BR /&gt;
&amp;gt; Here is the code:&lt;BR /&gt;
&amp;gt;&lt;BR /&gt;
&amp;gt; Private Sub Excel_Running_Check()&lt;BR /&gt;
&amp;gt; Dim excelApp As Excel.Application&lt;BR /&gt;
&amp;gt; On Error Resume Next&lt;BR /&gt;
&amp;gt;   Err.Clear&lt;BR /&gt;
&amp;gt;   Set excelApp = GetObject(, "excel.application")&lt;BR /&gt;
&amp;gt;   If Err &amp;lt;&amp;gt; 0 Then&lt;BR /&gt;
&amp;gt;     Err.Clear&lt;BR /&gt;
&amp;gt;   Else&lt;BR /&gt;
&amp;gt;     excelApp.DisplayAlerts = False&lt;BR /&gt;
&amp;gt;     excelApp.ActiveWorkbook.Close&lt;BR /&gt;
&amp;gt;     excelApp.Quit&lt;BR /&gt;
&amp;gt;     Set excelApp = Nothing&lt;BR /&gt;
&amp;gt; End Sub&lt;BR /&gt;
&amp;gt;&lt;BR /&gt;
&amp;gt; The idea for this sub is to check for a running instance of excel.  If it&lt;BR /&gt;
&amp;gt; exists then close it down before opening up another instance of excel.&lt;BR /&gt;
The&lt;BR /&gt;
&amp;gt; problem is that excel still remains memory resident.  I verify this by&lt;BR /&gt;
using&lt;BR /&gt;
&amp;gt; ctrl-alt-del to open the task manager and notice that excel is still&lt;BR /&gt;
&amp;gt; running.   The only way I can get excel to stop running is to close down&lt;BR /&gt;
my&lt;BR /&gt;
&amp;gt; application with the End function.  I've seen similar posts all over the&lt;BR /&gt;
&amp;gt; internet but I haven't found an answer to it yet.  The fact that excel is&lt;BR /&gt;
&amp;gt; not released from memory causes problems when reopening excel through my&lt;BR /&gt;
&amp;gt; program.  Subsequent intances of spreadsheets are not formatted&lt;BR /&gt;
&amp;gt; programatically as is intended through my code.  Several instances of&lt;BR /&gt;
excel&lt;BR /&gt;
&amp;gt; remain running in task manager.  Please help.&lt;BR /&gt;
&amp;gt;&lt;BR /&gt;
&amp;gt;&lt;/REICHHARDTG&gt;</description>
      <pubDate>Tue, 29 Apr 2003 08:03:46 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/how-to-end-excel-from-vba/m-p/304810#M64004</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2003-04-29T08:03:46Z</dc:date>
    </item>
    <item>
      <title>Re:</title>
      <link>https://forums.autodesk.com/t5/vba-forum/how-to-end-excel-from-vba/m-p/304811#M64005</link>
      <description>I have the same behaviour with Visual Lisp see:&lt;BR /&gt;
&lt;BR /&gt;
customization: Excel Quit: new behaviour (04/29/03)&lt;BR /&gt;
&lt;BR /&gt;
I am searching a solution.&lt;BR /&gt;
&lt;BR /&gt;
Marco&lt;BR /&gt;
&lt;BR /&gt;
-------------------------------------------------------&lt;BR /&gt;
&lt;BR /&gt;
1) if I run this function the Excel app is closed correctly&lt;BR /&gt;
   but if I activate the lines with ";&amp;lt;&amp;lt;" Excel is not closed&lt;BR /&gt;
   completely and in task manager remain a instance, why?&lt;BR /&gt;
&lt;BR /&gt;
2) is it a method to find any "non-released" objects?&lt;BR /&gt;
&lt;BR /&gt;
--&lt;BR /&gt;
&lt;BR /&gt;
; A2K2 - SDI = 1 - Excel not running&lt;BR /&gt;
(defun C:XlTest ( )&lt;BR /&gt;
  (vl-load-com)&lt;BR /&gt;
  (setq&lt;BR /&gt;
     *ExcelApp*  (vlax-get-or-create-object "Excel.Application")&lt;BR /&gt;
     *ActiveWbk*&lt;BR /&gt;
       (vlax-invoke-method&lt;BR /&gt;
         (vlax-get-property *ExcelApp* 'WorkBooks) 'Add&lt;BR /&gt;
       )&lt;BR /&gt;
     *ActiveSht* (vlax-get-property *ExcelApp* 'ActiveSheet)&lt;BR /&gt;
     *ActiveCls* (vlax-get-property *ActiveSht* 'Cells)&lt;BR /&gt;
  )&lt;BR /&gt;
  (vla-put-visible *ExcelApp* 1)&lt;BR /&gt;
  (setq&lt;BR /&gt;
    SttCll (vlax-variant-value&lt;BR /&gt;
             (vlax-get-property&lt;BR /&gt;
               *ActiveCls* 'Item&lt;BR /&gt;
               (vlax-make-variant 4) (vlax-make-variant  4)&lt;BR /&gt;
             )&lt;BR /&gt;
           )&lt;BR /&gt;
    EndCll (vlax-variant-value&lt;BR /&gt;
             (vlax-get-property&lt;BR /&gt;
               *ActiveCls* 'Item&lt;BR /&gt;
               (vlax-make-variant 4) (vlax-make-variant 10)&lt;BR /&gt;
             )&lt;BR /&gt;
           )&lt;BR /&gt;
;   RngObj (vlax-get-property *ActiveSht* 'Range SttCll EndCll);&amp;lt;&amp;lt;&lt;BR /&gt;
  )&lt;BR /&gt;
  (vlax-release-object SttCll)&lt;BR /&gt;
  (vlax-release-object EndCll)&lt;BR /&gt;
; (vlax-release-object RngObj) ;&amp;lt;&amp;lt;&lt;BR /&gt;
  (setq RngObj nil SttCll nil EndCll nil)&lt;BR /&gt;
  (vlax-release-object *ActiveCls*)&lt;BR /&gt;
  (vlax-release-object *ActiveSht*)&lt;BR /&gt;
  (vlax-invoke-method  *ActiveWbk* 'Close :vlax-False)&lt;BR /&gt;
  (vlax-release-object *ActiveWbk*)&lt;BR /&gt;
  (vlax-invoke-method  *ExcelApp* 'QUIT)&lt;BR /&gt;
  (vlax-release-object *ExcelApp*)&lt;BR /&gt;
  (setq&lt;BR /&gt;
    *ExcelApp* nil  *ActiveWbk* nil  *ActiveSht* nil  *ActiveCls* nil&lt;BR /&gt;
  )&lt;BR /&gt;
  (gc)&lt;BR /&gt;
)&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
-- &lt;BR /&gt;
&lt;BR /&gt;
"Ed Jobe" &lt;EDLJOBE&gt; ha scritto nel messaggio&lt;BR /&gt;
news:8483292FF87D571DBF50F70EDED0016D@in.WebX.maYIadrTaRb...&lt;BR /&gt;
&amp;gt; This is a known problem with Excel. I suspect that you havn't shown all of&lt;BR /&gt;
&amp;gt; your code, but the rule here is to clear up all your object variables in&lt;BR /&gt;
the&lt;BR /&gt;
&amp;gt; reverse of the hierarchical order that you derived them. For example, you&lt;BR /&gt;
&amp;gt; start with an application object, then use it to create a workbook object,&lt;BR /&gt;
&amp;gt; and then use that object to create a sheet object. Before you close the&lt;BR /&gt;
app,&lt;BR /&gt;
&amp;gt; you need to set to nothing, first the sheet object and then the workbook&lt;BR /&gt;
&amp;gt; object. Then you can deal with the app object.&lt;BR /&gt;
&amp;gt;&lt;BR /&gt;
&amp;gt; --&lt;BR /&gt;
&amp;gt; Ed&lt;BR /&gt;
&amp;gt; --&lt;BR /&gt;
&amp;gt;&lt;/EDLJOBE&gt;</description>
      <pubDate>Wed, 30 Apr 2003 21:19:01 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/how-to-end-excel-from-vba/m-p/304811#M64005</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2003-04-30T21:19:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to end Excel from VBA</title>
      <link>https://forums.autodesk.com/t5/vba-forum/how-to-end-excel-from-vba/m-p/304812#M64006</link>
      <description>I have has the same problem but finally found a solution!&lt;BR /&gt;
The problem fore me would occur when I was formatting the cells in the worksheet.&lt;BR /&gt;
Avoid using .Select. ActiveSheet, ActiveCell, With, .Range, and .Select.&lt;BR /&gt;
Instead use the object reference.&lt;BR /&gt;
For example instead of :&lt;BR /&gt;
Range("A1:A3").Font.Bold = True&lt;BR /&gt;
try:&lt;BR /&gt;
objSheet.Range("A1:A3").Font.Bold = True&lt;BR /&gt;
&lt;BR /&gt;
Instead of&lt;BR /&gt;
'With objSheet.Rows("4")&lt;BR /&gt;
       .HorizontalAlignment = xlCenter&lt;BR /&gt;
        .VerticalAlignment = xlCenter&lt;BR /&gt;
        .WrapText = True&lt;BR /&gt;
        .Orientation = 0&lt;BR /&gt;
        .AddIndent = False&lt;BR /&gt;
        .IndentLevel = 0&lt;BR /&gt;
        .ShrinkToFit = False&lt;BR /&gt;
        .MergeCells = False&lt;BR /&gt;
    End With&lt;BR /&gt;
&lt;BR /&gt;
try:&lt;BR /&gt;
&lt;BR /&gt;
        objSheet.Rows("4").HorizontalAlignment = xlCenter&lt;BR /&gt;
        objSheet.Rows("4").VerticalAlignment = xlCenter&lt;BR /&gt;
        objSheet.Rows("4").WrapText = True&lt;BR /&gt;
        objSheet.Rows("4").Orientation = 0&lt;BR /&gt;
        objSheet.Rows("4").AddIndent = False&lt;BR /&gt;
        objSheet.Rows("4").IndentLevel = 0&lt;BR /&gt;
        objSheet.Rows("4").ShrinkToFit = False&lt;BR /&gt;
        objSheet.Rows("4").MergeCells = False&lt;BR /&gt;
&lt;BR /&gt;
When you're ready to close Excel you will want to use&lt;BR /&gt;
objExcel.quit&lt;BR /&gt;
set objExcel = nothing&lt;BR /&gt;
&lt;BR /&gt;
It works great for me.&lt;BR /&gt;
Hope this helps</description>
      <pubDate>Wed, 11 May 2005 13:16:44 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/how-to-end-excel-from-vba/m-p/304812#M64006</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2005-05-11T13:16:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to end Excel from VBA</title>
      <link>https://forums.autodesk.com/t5/vba-forum/how-to-end-excel-from-vba/m-p/304813#M64007</link>
      <description>As pointed out it is a long standing issue.  Try this as a long standing solution:&lt;BR /&gt;
&lt;BR /&gt;
http://support.microsoft.com/default.aspx?scid=kb;en-us;132535&lt;BR /&gt;
&lt;BR /&gt;
Good luck,&lt;BR /&gt;
&lt;BR /&gt;
Bob Coward&lt;BR /&gt;
CADS, Inc&lt;BR /&gt;
&lt;BR /&gt;
800-366-0946&lt;BR /&gt;
bcoward@mindspring.com</description>
      <pubDate>Wed, 11 May 2005 13:55:34 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/how-to-end-excel-from-vba/m-p/304813#M64007</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2005-05-11T13:55:34Z</dc:date>
    </item>
    <item>
      <title>Re:</title>
      <link>https://forums.autodesk.com/t5/vba-forum/how-to-end-excel-from-vba/m-p/304814#M64008</link>
      <description>Marc...&lt;BR /&gt;
&lt;BR /&gt;
I am trying to write a piece of LISP code to answer an "alert box" that pops up when I load a linked Excel file...&lt;BR /&gt;
&lt;BR /&gt;
I found your email in a LISP program (MsXUtl01.LSP)…you look to be an Excel-AutoCAD expert, so I am asking you this question!! (Thanks!)&lt;BR /&gt;
&lt;BR /&gt;
I have a problem I’m working on…I need to “translate” a line of VBA code into its LISP equivalent…&lt;BR /&gt;
&lt;BR /&gt;
Set xlbook = xlapp.Workbooks.Open(path &amp;amp; "\" &amp;amp; dwgname &amp;amp; "-" &amp;amp; "KeyNotes Data Main.xls", UpdateLinks:=3)&lt;BR /&gt;
&lt;BR /&gt;
This line of VBA code opens an Excel file and answers “yes” to an alert asking “Do you want to Update Links?” … “Yes / No”…&lt;BR /&gt;
&lt;BR /&gt;
Here’s what I have so far for my LISP…and it works, except that the program stops when the alert is displayed asking the user to indicate his Link Updating preference…&lt;BR /&gt;
&lt;BR /&gt;
        ((setq excelsession (vlax-get-or-create-object "Excel.Application"))&lt;BR /&gt;
          (vlax-invoke-method&lt;BR /&gt;
            (vlax-get-property excelsession 'WorkBooks)&lt;BR /&gt;
            'Open fn                       ßHOW DO I “FEED” A RESPONSE TO EXCEL WHEN IT ASKS IF I WANT TO UPDATE LINKS??? (“YES”)&lt;BR /&gt;
          )&lt;BR /&gt;
          (if (= (strcase dmode) "SHOW")&lt;BR /&gt;
            (vla-put-visible excelsession 1)&lt;BR /&gt;
            (vla-put-visible excelsession 0)&lt;BR /&gt;
          )&lt;BR /&gt;
        )&lt;BR /&gt;
&lt;BR /&gt;
Any help or suggestion will be greatly appreciated!&lt;BR /&gt;
&lt;BR /&gt;
Pete</description>
      <pubDate>Thu, 20 Apr 2006 13:50:14 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/how-to-end-excel-from-vba/m-p/304814#M64008</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2006-04-20T13:50:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to end Excel from VBA</title>
      <link>https://forums.autodesk.com/t5/vba-forum/how-to-end-excel-from-vba/m-p/304815#M64009</link>
      <description>The Microsoft Knowledge Base article referred to seems to apply to FoxPro...&lt;BR /&gt;
&lt;BR /&gt;
APPLIES TO&lt;BR /&gt;
• Microsoft Visual FoxPro 3.0 Standard Edition &lt;BR /&gt;
• Microsoft Visual FoxPro 5.0 Standard Edition &lt;BR /&gt;
• Microsoft Visual FoxPro 5.0a &lt;BR /&gt;
• Microsoft Visual FoxPro 6.0 Professional Edition &lt;BR /&gt;
&lt;BR /&gt;
Is there a VBA specific solution?&lt;BR /&gt;
&lt;BR /&gt;
Thanks!</description>
      <pubDate>Mon, 27 Nov 2006 03:25:59 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/how-to-end-excel-from-vba/m-p/304815#M64009</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2006-11-27T03:25:59Z</dc:date>
    </item>
    <item>
      <title>Re: How to end Excel from VBA</title>
      <link>https://forums.autodesk.com/t5/vba-forum/how-to-end-excel-from-vba/m-p/304816#M64010</link>
      <description>Hi,&lt;BR /&gt;
I have to tryed to rewrite this code on pure VBA with using&lt;BR /&gt;
of API functions see my example&lt;BR /&gt;
Make sure that in VBEditor -&amp;gt;Tools-&amp;gt;Options-&amp;gt;General&lt;BR /&gt;
was checked "Break on Unhandled Errors" button&lt;BR /&gt;
Feel free to adapt it to your suit&lt;BR /&gt;
&lt;BR /&gt;
Option Explicit&lt;BR /&gt;
     Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)&lt;BR /&gt;
     Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long&lt;BR /&gt;
     Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Integer, ByVal lParam As Any) As Long&lt;BR /&gt;
     Const WT_SLEEP = 2500&lt;BR /&gt;
     Const WM_CLOSE = &amp;amp;H10&lt;BR /&gt;
     Const WM_ACTIVATEAPP = &amp;amp;H1C&lt;BR /&gt;
     Const WM_USER = 1024&lt;BR /&gt;
     Const gcClassnameMSExcel = "XLMAIN"&lt;BR /&gt;
&lt;BR /&gt;
Sub TestExcelQuit()&lt;BR /&gt;
Dim xlApp As Object&lt;BR /&gt;
Dim xlBook As Object&lt;BR /&gt;
Dim xlSheet As Object&lt;BR /&gt;
Dim hwnd As Long&lt;BR /&gt;
Dim WhatD As Long&lt;BR /&gt;
On Error Resume Next&lt;BR /&gt;
Set xlApp = Nothing&lt;BR /&gt;
Set xlApp = GetObject(, "Excel.Application")&lt;BR /&gt;
If Err.Number  0 Then 'read this line as If Err.Number not equal zero&lt;BR /&gt;
'because this symbol not shown correctly in this code&lt;BR /&gt;
'I don't know why&lt;BR /&gt;
Set xlApp = CreateObject("Excel.Application")&lt;BR /&gt;
End If&lt;BR /&gt;
Err.Clear&lt;BR /&gt;
On Error GoTo Err_Control&lt;BR /&gt;
MsgBox "Sleep 2.5 seconds"&lt;BR /&gt;
Set xlBook = xlApp.Workbooks.Add&lt;BR /&gt;
Set xlSheet = xlBook.worksheets(1)&lt;BR /&gt;
xlSheet.Application.Visible = True&lt;BR /&gt;
&lt;BR /&gt;
Sleep WT_SLEEP ' pause 2.5 sec&lt;BR /&gt;
&lt;BR /&gt;
xlBook.Close Savechanges:=False&lt;BR /&gt;
Set xlSheet = Nothing&lt;BR /&gt;
Set xlBook = Nothing&lt;BR /&gt;
&lt;BR /&gt;
     hwnd = FindWindow(gcClassnameMSExcel, 0)&lt;BR /&gt;
&lt;BR /&gt;
     Do While hwnd &amp;gt; 0&lt;BR /&gt;
          'WhatD = SendMessage(hwnd, WM_USER + 18, 0, ByVal 0&amp;amp;)    ' Microsoft Excel 95&lt;BR /&gt;
          WhatD = SendMessage(hwnd, WM_ACTIVATEAPP, 0, ByVal 0&amp;amp;)   ' Microsoft Office 2000 or Microsoft Office XP&lt;BR /&gt;
          'Set xlApp = GetObject(, "Excel.Application")&lt;BR /&gt;
          xlApp.Quit&lt;BR /&gt;
          hwnd = FindWindow(gcClassnameMSExcel, 0)&lt;BR /&gt;
&lt;BR /&gt;
     Loop&lt;BR /&gt;
Set xlApp = Nothing&lt;BR /&gt;
&lt;BR /&gt;
Err_Control:&lt;BR /&gt;
If Err Then&lt;BR /&gt;
MsgBox Err.Description&lt;BR /&gt;
Set xlSheet = Nothing&lt;BR /&gt;
Set xlBook = Nothing&lt;BR /&gt;
Set xlApp = Nothing&lt;BR /&gt;
End If&lt;BR /&gt;
&lt;BR /&gt;
End Sub&lt;BR /&gt;
&lt;BR /&gt;
Fatty&lt;BR /&gt;
&lt;BR /&gt;
~'J'~

Message was edited by: Fatty</description>
      <pubDate>Mon, 27 Nov 2006 12:44:49 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/how-to-end-excel-from-vba/m-p/304816#M64010</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2006-11-27T12:44:49Z</dc:date>
    </item>
    <item>
      <title>Re: How to end Excel from VBA</title>
      <link>https://forums.autodesk.com/t5/vba-forum/how-to-end-excel-from-vba/m-p/304817#M64011</link>
      <description>http://www.devcity.net/Articles/239/1/article.aspx</description>
      <pubDate>Tue, 28 Nov 2006 16:40:57 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/how-to-end-excel-from-vba/m-p/304817#M64011</guid>
      <dc:creator>Mikko</dc:creator>
      <dc:date>2006-11-28T16:40:57Z</dc:date>
    </item>
  </channel>
</rss>

