Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Check to see if Excel has closed

I am building a VB6 application that uses Automation to populate an Excel
worksheet with data from a database table. When cleaning up as the
application closes, is there any way to check to see if the user has
manually closed the Automation server (Excel session) before I attempt to
close it in code?

Bob


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,290
Default Check to see if Excel has closed

Bob,
Something similar to the following (used to check for Word"),
should work for you...
'------------------------
Public appWord As Word.Application

Sub CreateWord()
Set appWord = New Word.Application
appWord.Visible = True
End Sub

'User could close application here

Sub CheckForWord()
If TypeName(appWord) = "Application" Then
appWord.Quit
Set appWord = Nothing
Else
'do something else
End If
End Sub
'------------------------
Regards,
Jim Cone
San Francisco, CA

"Robert A. Boudra" wrote in message ...
I am building a VB6 application that uses Automation to populate an Excel
worksheet with data from a database table. When cleaning up as the
application closes, is there any way to check to see if the user has
manually closed the Automation server (Excel session) before I attempt to
close it in code?
Bob


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Check to see if Excel has closed

Jim:

When I try that, it doesn't seem to work. The "TypeName" function still
returns the object type of "Application", even if the user has closed the
Excel Session.

Bob

"Jim Cone" wrote in message
...
Bob,
Something similar to the following (used to check for Word"),
should work for you...
'------------------------
Public appWord As Word.Application

Sub CreateWord()
Set appWord = New Word.Application
appWord.Visible = True
End Sub

'User could close application here

Sub CheckForWord()
If TypeName(appWord) = "Application" Then
appWord.Quit
Set appWord = Nothing
Else
'do something else
End If
End Sub
'------------------------
Regards,
Jim Cone
San Francisco, CA

"Robert A. Boudra" wrote in message

...
I am building a VB6 application that uses Automation to populate an

Excel
worksheet with data from a database table. When cleaning up as the
application closes, is there any way to check to see if the user has
manually closed the Automation server (Excel session) before I attempt

to
close it in code?
Bob




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Check to see if Excel has closed

Don't know if this is any help, but try to look on help in excel or vb6.0 on
"GetObject".

Grtz,
James

"Robert A. Boudra" schreef in bericht
...
Jim:

When I try that, it doesn't seem to work. The "TypeName" function still
returns the object type of "Application", even if the user has closed the
Excel Session.

Bob

"Jim Cone" wrote in message
...
Bob,
Something similar to the following (used to check for Word"),
should work for you...
'------------------------
Public appWord As Word.Application

Sub CreateWord()
Set appWord = New Word.Application
appWord.Visible = True
End Sub

'User could close application here

Sub CheckForWord()
If TypeName(appWord) = "Application" Then
appWord.Quit
Set appWord = Nothing
Else
'do something else
End If
End Sub
'------------------------
Regards,
Jim Cone
San Francisco, CA

"Robert A. Boudra" wrote in message

...
I am building a VB6 application that uses Automation to populate an

Excel
worksheet with data from a database table. When cleaning up as the
application closes, is there any way to check to see if the user has
manually closed the Automation server (Excel session) before I attempt

to
close it in code?
Bob






  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,290
Default Check to see if Excel has closed

Bob,
Is there a hidden instance of Excel still running?
Check in Windows Task Manager.
Regards,
Jim Cone
San Francisco, CA

"Robert A. Boudra" wrote in message ...
Jim:
When I try that, it doesn't seem to work. The "TypeName" function still
returns the object type of "Application", even if the user has closed the
Excel Session.
Bob


"Jim Cone" wrote in message
...
Bob,
Something similar to the following (used to check for Word"),
should work for you...
'------------------------
Public appWord As Word.Application

Sub CreateWord()
Set appWord = New Word.Application
appWord.Visible = True
End Sub

'User could close application here

Sub CheckForWord()
If TypeName(appWord) = "Application" Then
appWord.Quit
Set appWord = Nothing
Else
'do something else
End If
End Sub
'------------------------
Regards,
Jim Cone
San Francisco, CA

"Robert A. Boudra" wrote in message

...
I am building a VB6 application that uses Automation to populate an

Excel
worksheet with data from a database table. When cleaning up as the
application closes, is there any way to check to see if the user has
manually closed the Automation server (Excel session) before I attempt

to close it in code?
Bob




  #6   Report Post  
Posted to microsoft.public.excel.programming
jaf jaf is offline
external usenet poster
 
Posts: 300
Default Check to see if Excel has closed

Hi Bob,
You should use createobject & getobject to start with. That way you have a
"pointer" to work with.
(with the proper error checking)
This code example is in your VB6 help file also.
http://msdn.microsoft.com/library/de...getobjectx.asp

The on real "problem" with getobject is it will find any running Excel
session.
The work-around is to specify the full path.
Note this line in the code: "Set MyXL = Getobject("c:\vb4\MYTEST.XLS")



--

John
johnf202 at hotmail dot com


"Robert A. Boudra" wrote in message
...
Jim:

When I try that, it doesn't seem to work. The "TypeName" function still
returns the object type of "Application", even if the user has closed the
Excel Session.

Bob

"Jim Cone" wrote in message
...
Bob,
Something similar to the following (used to check for Word"),
should work for you...
'------------------------
Public appWord As Word.Application

Sub CreateWord()
Set appWord = New Word.Application
appWord.Visible = True
End Sub

'User could close application here

Sub CheckForWord()
If TypeName(appWord) = "Application" Then
appWord.Quit
Set appWord = Nothing
Else
'do something else
End If
End Sub
'------------------------
Regards,
Jim Cone
San Francisco, CA

"Robert A. Boudra" wrote in message

...
I am building a VB6 application that uses Automation to populate an

Excel
worksheet with data from a database table. When cleaning up as the
application closes, is there any way to check to see if the user has
manually closed the Automation server (Excel session) before I attempt

to
close it in code?
Bob






  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Check to see if Excel has closed

Hi Jim:

Yes, there continues to be an existing instance of Excel running even though
the user has closed the window. It only goes away when the object variable
loses scope or is explicitly set to Nothing. This doesn't really do me any
good, because the reason I'm trying to find out if it's still open is so I
can allow the user to save the active worksheet, if it's stll present. If I
set the object variable to Nothing, then I can't offer that option anyway.

Bob

"Jim Cone" wrote in message
...
Bob,
Is there a hidden instance of Excel still running?
Check in Windows Task Manager.
Regards,
Jim Cone
San Francisco, CA

"Robert A. Boudra" wrote in message

...
Jim:
When I try that, it doesn't seem to work. The "TypeName" function still
returns the object type of "Application", even if the user has closed

the
Excel Session.
Bob


"Jim Cone" wrote in message
...
Bob,
Something similar to the following (used to check for Word"),
should work for you...
'------------------------
Public appWord As Word.Application

Sub CreateWord()
Set appWord = New Word.Application
appWord.Visible = True
End Sub

'User could close application here

Sub CheckForWord()
If TypeName(appWord) = "Application" Then
appWord.Quit
Set appWord = Nothing
Else
'do something else
End If
End Sub
'------------------------
Regards,
Jim Cone
San Francisco, CA

"Robert A. Boudra" wrote in message

...
I am building a VB6 application that uses Automation to populate an

Excel
worksheet with data from a database table. When cleaning up as the
application closes, is there any way to check to see if the user has
manually closed the Automation server (Excel session) before I

attempt
to close it in code?
Bob




  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,290
Default Check to see if Excel has closed

Bob,

Code to automate Excel can very easily create "orphan" references
that prevent the application from quitting even though the application has
been "closed". I have taken the liberty of listing some causes
of the problem. Hope it helps...
'-------------------------------------------------------------
Here are some general guidelines to use when automating Excel...
'Jim Cone - San Francisco, CA

1. Set a reference to the primary Excel objects used in your program.
Dim xlApp As Excel.Application
Dim WB As Excel.Workbook
Dim WS As Excel.Worksheet

Set xlApp = New Excel.Application
Set WB = xlApp.Workbooks.Add
Set WS = WB.Sheets(1)

Use the appropriate reference Every Time you make reference to a spreadsheet.
Do not use Range(xx) - use WS.Range(xx)
Cells should be WS.Cells(10, 20) or _
WS.Range(WS.Cells(10, 20), WS.Cells(20, 40))

2. Avoid the use of ActiveSheet, ActiveWorkbook, Selection etc.
Use your object references.

3. Avoid the use of the "With" construct.

4. Set all objects to Nothing in the proper order - child then parent.
Set WS = Nothing
WB.Close SaveChanges:=True 'your choice
Set WB = Nothing
xlApp.Quit
Set xlApp = Nothing

Violating any of these guidelines can leave "orphans" that still refer
to Excel and prevent the application from closing.

'------------------------------------------------------------

Articles dealing with unqualified references and automation
application not quitting.

1. 178510 - PRB: Excel Automation Fails Second Time Code Runs
http://support.microsoft.com/default...en-us%3b178510
Summary: While running code that uses Automation to control Microsoft Excel,
one of the following errors may occur: With Microsoft Excel 97 and later, you receive the error:
Run-time error '1004': Method '<name of method' of object '_Global' failed -or-...

2. 189618 - PRB: Automation Error Calling Unqualified Method or Property
http://support.microsoft.com/default...en-us%3b189618
Summary: While running code that uses Automation to control Microsoft Word 97,
Word 2000, or Word 2002, you may receive one of the following error messages:
Run-time error '-2147023174' (800706ba) Automation error -or- Run-time error '462': The remote server...

3. 199219 - XL2000: Automation Doesn't Release Excel Object from Memory
http://support.microsoft.com/default...;en-us;q199219
When you run a macro that uses automation to create a Microsoft Excel object (instance),
the Excel object does not exit from memory when you specify.
If you create another Excel object after quitting the first, a second instance is in memory.
This problem occurs when your macro uses a "WITH" statement that refers to the automation object.

4. 319832 - INFO: Error or Unexpected Behavior with Office Automation
When You Use Early Binding in Visual Basic
http://support.microsoft.com/default...en-us%3b319832
Summary: When you automate a Microsoft Office application,
you may receive an error message or you may experience unexpected behavior, as follows.
You may receive one of the following error messages: Error 91: Object variable or With block variable not set....

5. 317109 - Visual Basic .Net & Visual C#
'-------------------------------------------------------------
Regards,
Jim Cone
San Francisco, CA


"Robert A. Boudra" wrote in message ...
Hi Jim:
Yes, there continues to be an existing instance of Excel running even though
the user has closed the window. It only goes away when the object variable
loses scope or is explicitly set to Nothing. This doesn't really do me any
good, because the reason I'm trying to find out if it's still open is so I
can allow the user to save the active worksheet, if it's stll present. If I
set the object variable to Nothing, then I can't offer that option anyway.
Bob

"Jim Cone" wrote in message
...
Bob,
Is there a hidden instance of Excel still running?
Check in Windows Task Manager.
Regards,
Jim Cone
San Francisco, CA

"Robert A. Boudra" wrote in message

...
Jim:
When I try that, it doesn't seem to work. The "TypeName" function still
returns the object type of "Application", even if the user has closed

the Excel Session.
Bob

-snip-
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to increment a value by 1 everytime excel is closed? ruzual Excel Discussion (Misc queries) 1 December 13th 06 06:59 PM
Where is the closed folder button in Excel? Susan ARC Excel Discussion (Misc queries) 2 July 25th 06 08:16 AM
Help - Closed excel doc with out saving it Sugan Excel Discussion (Misc queries) 3 May 16th 06 01:00 PM
why do all files get closed when i only close one in excel? carrie Excel Discussion (Misc queries) 1 November 28th 05 06:45 PM
ADO - recordset - closed excel workbook graham d Excel Programming 9 October 21st 04 04:08 PM


All times are GMT +1. The time now is 10:12 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"