Solved

Killing specific processes -  I have multiple EXCEL spreadsheets running in real time.  They all need to be closed once a day automatically.  Is there a way to tag each process?

Posted on 2012-03-12
8
372 Views
Last Modified: 2012-06-22
I have multiple versions of excel running real time applications.   The programs have to be stopped and restarted during off-hours.   Some processes need to be stopped at one time and others at another time.   The processes are on several users machines.   Is there a way to identify a process so a script can be written to save and close excel for later restart.   My IT guy says he can't tell one EXCEL process from another - so he cant target which one to close down.
0
Comment
Question by:dma70
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 40

Expert Comment

by:Kyle Abrahams
ID: 37710309
Yes, this can be done via excel VBA.

http://www.exceltip.com/st/Determine_if_a_workbook_is_already_open_using_VBA_in_Microsoft_Excel/472.html

I would create a generic workbook on each computer.  Then exec the workbook with the auto_open macro to close needed workbooks, saving as needed.
0
 
LVL 1

Author Comment

by:dma70
ID: 37710362
Not trying to determine if workbook is open.  It will be.  Trying to figure out how to identify which excel process is which.  Assume there are 10 of them and I want to shut down only one.  How does the OS script identify which process to close?
0
 
LVL 3

Accepted Solution

by:
DaFranker earned 300 total points
ID: 37710408
If you're familiar with inter-application code and the MS Office object models (Excel's in particular, of course), you could use the excel objects to specify which workbooks to close. The interface and specific method to go about doing this depends largely on which language your script will be written in.

You could also, in theory, write it (the script) in the excel sheets themselves, though the code would probably be less efficient than an external script for this particular purpose and you might end up having the additional problem of forcing your users to confirm macro activation each time one of these workbooks opens, depending on their individual security settings. Of course, if you're already using VBA code for your realtime processing in the excel documents, then this option might be worth considering more seriously.

To my knowledge, there is no way within excel to "tag" a process from the workbook without an external plugin or library being referenced, which might raise additional security concerns as and/or deployment overhead if you need to distribute the library along with the workbooks. One single process can open more than one workbook, or even none. This makes most of the data you'd normally use to identify duplicate processes volatile and unreliable.

EDIT: ged325's proposed solution would also work, and is a good simple hack solution that seems like it would suit your needs. He referred you to the instructions on detecting an open workbook simply because that's what you need to do first to guarantee that there won't be conflicts. As for identification, you would close specific workbooks rather than "excel processes", which would still achieve your objectives, since when a workbook is closed programmatically and was the last workbook of that process, the process generally shuts down.
0
Scamming the Scammers!

Have you ever heard of Scam Baiting?
It's a highly entertaining sport that you can participate in.
Introduction to beating scammers at their own game and how you can help
Share your thoughts, ideas and experiences on the topic.
Links to top Anti-Scam resources provided.

 
LVL 7

Expert Comment

by:CloudedTurtle
ID: 37711484
Using C# you can loop through the processes using System.Diagnostic. You can use the "MainWindowTitle" property to determin the name of the file currently opened by that process... Here is a short snippet that loops through the Excel processes:
foreach (Process p in Process.GetProcesses())
            {
                if (p.ProcessName == "EXCEL")
                {                                        
                    listBox1.Items.Add(p.MainWindowTitle);
                }                

            }

Open in new window

once you have the right process, you can use the p.Kill method to terminate the process.

Note: You could also use Office Interop to attach to the Excel Process, and save any updates and close properly instead of a Kill method. refer to MSDN OfficeInterop.Excel for more details.
0
 
LVL 40

Expert Comment

by:Kyle Abrahams
ID: 37711662
"Not trying to determine if workbook is open.  It will be."

Never assume that the program will work exactly as you intend it to.  Most errors in programs are caused by unforseen circumstances.  For instance, a user logs out their machine but leaves it on.  You call the script against that computer to close the workbook and viola, the code just broke.  Always better to be safe than sorry.


As DaFranker pointed out (thanks for the verbose explination . . . that was exactly on target), the referenced code was to find the workbook if it's open, and from there you can close the workbook forcing the save


CloudedTurtle's system.Reflection method is an elegant solution that can also accomplish the same task.  

Regardless there are multiple ways of achieving your ends.
0
 
LVL 1

Author Comment

by:dma70
ID: 37711721
My IT guy doesn't know c# - but I think these answers are going in the right direction.  Being able to drill down and get the name of the spreadsheet sounds like a viable solution if it were easy to program.   Seems like the best solution is to put a clock into vb code and when the right time comes shut the program down.
0
 
LVL 7

Expert Comment

by:CloudedTurtle
ID: 37711748
Handle the timing using the Windows Scheduler, this is much easier, and less problematic than having an application that is always running (less chance of memory leaks).

PS: There are equivalent methods that I showed in C# available for VB.Net as well. i just don't know them. :-)
0
 
LVL 1

Author Comment

by:dma70
ID: 37711770
thank you  -
0

Featured Post

SendBlaster Pro 4 - Bulk Email Sending Software

SendBlaster 4 Pro - Best Bulk Emailing Sending Software
Automatic Subscribe / Unsubscribe Processing
Great for Newsletters & Mass Mailings
Optional HTML & Text Composition
Integration with Google Features
Built in Spam Score Checking
Free Professional Templates - Feature Packed!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

First some basics on Windows 7 Backup.  It has 2 components one is a file based backup which is stored in .zip files each zip is split at around 200 Megabytes and there is the Image Backup which is as the name implies a total image of the partition …
There are many software programs on offer that will claim to magically speed up your computer. The best advice I can give you is to avoid them like the plague, because they will often cause far more problems than they solve. Try some of these "do it…
This Micro Tutorial will go in depth within Systems and Security in Windows 7 and will go into detail regarding Action Center, Windows Firewall, System, etc. This will be demonstrated using Windows 7 operating system.
This Micro Tutorial will give you a introduction in two parts how to utilize Windows Live Movie Maker to its maximum capability. This will be demonstrated using Windows Live Movie Maker on Windows 7 operating system.

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question