Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old September 28th, 2006, 07:17 PM
Authorized User
 
Join Date: Jul 2004
Location: , , .
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Default end process in task mgr

I have a .mdb that creates a excel spreadsheet. The .mdb saves the spreadsheet and releases excel from memory.

appExcel.close 'close excel application
set appExcel to nothing 'releasing Excel application
set bks to nothing 'releasing the workbook
set wks to nothing 'releasing the worksheet

However, if you open the task mgr after running the script, I still see Excel.exe under the process tab. I have to manually select excel.exe in the task mgr and click end process.

If I dont do this and try tu run the script (in access) again, it error out. Is there another call to end this process programatically from access? Is it an API call?

Reply With Quote
  #2 (permalink)  
Old September 29th, 2006, 06:44 AM
Friend of Wrox
Points: 9,611, Level: 42
Points: 9,611, Level: 42 Points: 9,611, Level: 42 Points: 9,611, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2004
Location: Washington, DC, USA.
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

You should check for the existence of the process at the beginning of each set of code for using the process, and if it is still running, kill the process first. I am sure that the posters here can show you a more elegant way, but here is the VBScript version that will run in your VBA:

Dim sComputer

sComputer = "."
Set objWMIService = GetObject("winmgmts:{impersonationLevel = impersonate}!\\" & strComputer & "\root\cimv2")
Set colProcesses = objWMIService.ExecQuery("SELECT * FROM Win32_Process")
For Each objProcess in colProcesses
    If objProcess.Name = "EXCEL.EXE" Then
           WScript.Echo objProcess.Name
           errReturnCode = objProcess.Terminate()
       End If
Next

I have tested this and it works on a Windows XP box.

HTH

mmcdonal
Reply With Quote
  #3 (permalink)  
Old September 29th, 2006, 06:46 AM
Friend of Wrox
Points: 9,611, Level: 42
Points: 9,611, Level: 42 Points: 9,611, Level: 42 Points: 9,611, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2004
Location: Washington, DC, USA.
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

Sorry, I left in some error checking code. Here is the code you should use:

Dim sComputer

sComputer = "."
Set objWMIService = GetObject("winmgmts:{impersonationLevel = impersonate}!\\" & strComputer & "\root\cimv2")
Set colProcesses = objWMIService.ExecQuery("SELECT * FROM Win32_Process")
For Each objProcess in colProcesses
    If objProcess.Name = "EXCEL.EXE" Then
           errReturnCode = objProcess.Terminate()
       End If
Next


mmcdonal
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to hide a process in task manager ri_shu C++ Programming 3 October 25th, 2007 10:22 PM
end process in task mgr bab02 Access VBA 4 August 13th, 2007 04:30 PM
Oracle back-end MS-Access 2003 client front-end Corey Access 2 February 16th, 2007 08:31 AM
how to hide a process in task manager ri_shu Visual C++ 0 April 5th, 2006 07:33 AM
how to hide the process from the task-manager ri_shu VB How-To 0 April 5th, 2006 07:28 AM



All times are GMT -4. The time now is 11:23 PM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.