The old application.quit problem

P

phreud

Hello,

I'm totally lost. I've been searching through these forums and th
internet for an answer, but I can't solve this problem. I have a splas
screen (userform) from which users can open different forms in m
application. The splash screen also has a quit button which is suppose
to close Excel down, but it still apperas in the task manager.

From what I've read, I think I understand the problem, but I have n
idea how to solve it. I'm not creating new instances in my code? No
sure if I should? Anyway, I'll give a brief explanation of what I'
doing:

I have 1 workbook with 3 sheets. I have a userform acting as a splas
screen. The first thing I do when someone opens my xls file is (cod
for ThisWorkbook):


Code
-------------------
Private Sub Workbook_Open()
Application.Visible = False
frmSplash.Show
End Sub

-------------------


On my splash screen, I have a quit button with the following code:


Code
-------------------
Private Sub btnQuit_Click()
For Each w In Application.Workbooks
w.Close False
Next w
Workbooks(1).Saved = True
ThisWorkbook.Close False
Application.Qui
-------------------


Clicking this still leaves the Excel process running. Can someon
please point me in the right direction?

Thankyou in advance
 
T

Tom Ogilvy

When you close the workbook with the code, the code stops running. You can
try reorganizing like this:

Private Sub btnQuit_Click()
For Each w In Application.Workbooks
if w.Name <> ThisWorkbook.Name then
w.Close False
End if
Next w
ThisWorkbook.Saved = True
Application.Quit
End Sub
 
D

Don Guillett

The problem is that you can't close the workbook and continue the code.
Think about it.
 
P

phreud

Tom:

Thanks alot! That sure solved the problem. It even works after I ope
up new forms and start fiddeling around. :)


Don:

That makes sense, ofcourse. I think I was intimidated by all thes
horror stories about keeping track of created instances I've bee
reading about :)


Thankyou both
 
H

Hafeez

I have a similar problem to this.
I've writen some code in Access which extracts,
manipulates and then ouputs the data to a user selected
workbook.

I create a single instance of an Excel Application object
and pass it to every routine that requires it.

Everything runs well and my output is correct. The only
problem I'm getting is that Excel is still under
the 'Processes' in Task Manager. This is a problem
because when I run the code again, it will stop at the
following routine.

Public Sub formatWorkbook(ByRef XL As Excel.Application,
ByVal strRangeName As String, _
ByRef FormatRange As Excel.Range)
'Copies format of named range to selection
XL.Goto (strRangeName)
If (Selection.Row >= FormatRange.Row) Then
Exit Sub
End If

sht.Cells(1, 1).Select
XL.Goto (strRangeName)
Selection.Copy
FormatRange.Select
FormatRange.PasteSpecial xlPasteFormats, , False, False
XL.ActiveSheet.Cells(1, 1).Select
End Sub

Specifically at "Selection.Row"

Please Help
Thanks





-----Original Message-----
Hello,

I'm totally lost. I've been searching through these forums and the
internet for an answer, but I can't solve this problem. I have a splash
screen (userform) from which users can open different forms in my
application. The splash screen also has a quit button which is supposed
to close Excel down, but it still apperas in the task manager.

From what I've read, I think I understand the problem, but I have no
idea how to solve it. I'm not creating new instances in my code? Not
sure if I should? Anyway, I'll give a brief explanation of what I'm
doing:

I have 1 workbook with 3 sheets. I have a userform acting as a splash
screen. The first thing I do when someone opens my xls file is (code
for ThisWorkbook):


Code:
 
S

Stephen Bullen

Hi Hafeez,
Public Sub formatWorkbook(ByRef XL As Excel.Application,
ByVal strRangeName As String, _
ByRef FormatRange As Excel.Range)
'Copies format of named range to selection
XL.Goto (strRangeName)
If (Selection.Row >= FormatRange.Row) Then
Exit Sub
End If

sht.Cells(1, 1).Select
XL.Goto (strRangeName)
Selection.Copy
FormatRange.Select
FormatRange.PasteSpecial xlPasteFormats, , False, False
XL.ActiveSheet.Cells(1, 1).Select
End Sub

Specifically at "Selection.Row"

Whenever you use any of Excel's 'global' objects, such as Cells,
Selection etc, you must prefix them with the instance of Excel you're
using:

Public Sub formatWorkbook(ByRef XL As Excel.Application,
ByVal strRangeName As String, _
ByRef FormatRange As Excel.Range)
'Copies format of named range to selection
XL.Goto (strRangeName)
If (XL.Selection.Row >= FormatRange.Row) Then
Exit Sub
End If

sht.Cells(1, 1).Select
XL.Goto (strRangeName)
XL.Selection.Copy
FormatRange.Select
FormatRange.PasteSpecial xlPasteFormats, , False, False
XL.ActiveSheet.Cells(1, 1).Select
End Sub



Regards

Stephen Bullen
Microsoft MVP - Excel
www.BMSLtd.ie
 
Top