PC Review


Reply
Thread Tools Rate Thread

can't get Excel to Quit

 
 
TADropik
Guest
Posts: n/a
 
      8th Jun 2009
I use the code below to create an Excel workbook and save it.
However, the OS doesn't let go of Excel. I still see EXCEL in the Task
Manager.


Dim objExcel As excel.Application
Dim objWorkbook As excel.Workbook
Dim objWorksheet As excel.Worksheet

Set objExcel = GetObject("", "excel.application")

objExcel.Visible = False

Set objWorkbook = objExcel.Workbooks.Add
objWorkbook.Worksheets.Add
Before:=objWorkbook.Worksheets(objWorkbook.Worksheets.Count)
objWorkbook.ActiveSheet.Name = "Data-Test"
Set objWorksheet = objWorkbook.Worksheets("Data-Test")
objWorksheet.Select

objExcel.ScreenUpdating = False

objWorksheet.Cells(1, 1) = "TESTING EXCEL"
objWorksheet.Cells(1, 1).ColumnWidth = 17
objWorksheet.Cells(1, 1).Font.Bold = True

objExcel.DisplayAlerts = False
objExcel.ActiveWorkbook.SaveAs ("C:\Excel\Test_Excel.xls")

objExcel.DisplayAlerts = True
objExcel.ScreenUpdating = True
objExcel.Quit

Set objWorksheet = Nothing
Set objWorkbook = Nothing
Set objExcel = Nothing
 
Reply With Quote
 
 
 
 
TADropik
Guest
Posts: n/a
 
      8th Jun 2009
What I did still didn't work.

I inserted the following line:
objExcel.ActiveWorkbook.Close

See code below:

Dim objExcel As excel.Application
Dim objWorkbook As excel.Workbook
Dim objWorksheet As excel.Worksheet

Set objExcel = GetObject("", "excel.application")

objExcel.Visible = False

Set objWorkbook = objExcel.Workbooks.Add
objWorkbook.Worksheets.Add
Before:=objWorkbook.Worksheets(objWorkbook.Worksheets.Count)
objWorkbook.ActiveSheet.Name = "Data-Test"
Set objWorksheet = objWorkbook.Worksheets("Data-Test")
objWorksheet.Select

objExcel.ScreenUpdating = False

objWorksheet.Cells(1, 1) = "TESTING EXCEL"
objWorksheet.Cells(1, 1).ColumnWidth = 17
objWorksheet.Cells(1, 1).Font.Bold = True

objExcel.DisplayAlerts = False
objExcel.ActiveWorkbook.SaveAs ("C:\Excel\Test_Excel.xls")
objExcel.ActiveWorkbook.Close

objExcel.DisplayAlerts = True
objExcel.ScreenUpdating = True
objExcel.Quit

Set objWorksheet = Nothing
Set objWorkbook = Nothing
Set objExcel = Nothing

"JimBurke via AccessMonster.com" wrote:

> I think you may still need to explicity close the workbook before quitting.
> Give that a shot.
>
> TADropik wrote:
> >I use the code below to create an Excel workbook and save it.
> >However, the OS doesn't let go of Excel. I still see EXCEL in the Task
> >Manager.
> >
> >Dim objExcel As excel.Application
> >Dim objWorkbook As excel.Workbook
> >Dim objWorksheet As excel.Worksheet
> >
> >Set objExcel = GetObject("", "excel.application")
> >
> >objExcel.Visible = False
> >
> >Set objWorkbook = objExcel.Workbooks.Add
> >objWorkbook.Worksheets.Add
> >Before:=objWorkbook.Worksheets(objWorkbook.Worksheets.Count)
> >objWorkbook.ActiveSheet.Name = "Data-Test"
> >Set objWorksheet = objWorkbook.Worksheets("Data-Test")
> >objWorksheet.Select
> >
> >objExcel.ScreenUpdating = False
> >
> >objWorksheet.Cells(1, 1) = "TESTING EXCEL"
> >objWorksheet.Cells(1, 1).ColumnWidth = 17
> >objWorksheet.Cells(1, 1).Font.Bold = True
> >
> >objExcel.DisplayAlerts = False
> >objExcel.ActiveWorkbook.SaveAs ("C:\Excel\Test_Excel.xls")
> >
> >objExcel.DisplayAlerts = True
> >objExcel.ScreenUpdating = True
> >objExcel.Quit
> >
> >Set objWorksheet = Nothing
> >Set objWorkbook = Nothing
> >Set objExcel = Nothing

>
> --
> Jim Burke
>
> Message posted via AccessMonster.com
> http://www.accessmonster.com/Uwe/For...dules/200906/1
>
>

 
Reply With Quote
 
Stewart Berman
Guest
Posts: n/a
 
      9th Jun 2009
This is systematic of the failure to destroy all objects before attempting to exit. In MS Access
the Access window doesn't close after the database is closed and clicking on the close button has no
effect. Excel hides but doesn't close.

Set all objects to nothing before they go out of scope. Failure to do so results in ghosts.

TADropik <(E-Mail Removed)> wrote:

>I use the code below to create an Excel workbook and save it.
>However, the OS doesn't let go of Excel. I still see EXCEL in the Task
>Manager.
>
>
>Dim objExcel As excel.Application
>Dim objWorkbook As excel.Workbook
>Dim objWorksheet As excel.Worksheet
>
>Set objExcel = GetObject("", "excel.application")
>
>objExcel.Visible = False
>
>Set objWorkbook = objExcel.Workbooks.Add
>objWorkbook.Worksheets.Add
>Before:=objWorkbook.Worksheets(objWorkbook.Worksheets.Count)
>objWorkbook.ActiveSheet.Name = "Data-Test"
>Set objWorksheet = objWorkbook.Worksheets("Data-Test")
>objWorksheet.Select
>
>objExcel.ScreenUpdating = False
>
>objWorksheet.Cells(1, 1) = "TESTING EXCEL"
>objWorksheet.Cells(1, 1).ColumnWidth = 17
>objWorksheet.Cells(1, 1).Font.Bold = True
>
>objExcel.DisplayAlerts = False
>objExcel.ActiveWorkbook.SaveAs ("C:\Excel\Test_Excel.xls")
>
>objExcel.DisplayAlerts = True
>objExcel.ScreenUpdating = True
>objExcel.Quit
>
>Set objWorksheet = Nothing
>Set objWorkbook = Nothing
>Set objExcel = Nothing


 
Reply With Quote
 
EricG
Guest
Posts: n/a
 
      9th Jun 2009
I copied this code into a blank module of a blank database and ran it. I had
to change the path for the Excel file to somewhere I had proper permissions,
and the code worked. Perhaps you are getting an error when trying to create
or save the file because of permissions? The "DisplayAlerts" might be
masking a problem - trying leaving alerts on to test your code. When it
works, you can turn it back off.

HTH,

Eric

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Quit Excel if ONLY Workbook Open else Close Excel instead Corey Microsoft Excel Programming 2 16th Jan 2007 05:41 AM
Excel Automation Code Fails To Quit Excel MikeC Microsoft Access VBA Modules 2 2nd Nov 2005 05:38 PM
Excel application.quit leaves instance of Excel running ChrisBowringGG@gmail.com Microsoft C# .NET 8 21st Sep 2005 10:39 AM
Excel.Application.Quit leaving Excel process stays active =?Utf-8?B?U2lnZ3k=?= Microsoft Excel Programming 1 20th Dec 2004 09:26 AM
Scripting Excel - EXCEL.EXE refuses to leave task manager after .Quit and =Nothing? Matt Microsoft Excel Programming 2 14th Dec 2004 02:36 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:00 PM.