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
371 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
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Possible fixes for Windows 7 and Windows Server 2008 updating problem. Solutions mentioned are from Microsoft themselves. I started a case with them from our Microsoft Silver Partner option to open a case and get direct support from Microsoft. If s…
While working, an annoying popup showing below will come and we cannot cancel or close it form the screen. The error message will come again and again.
In this video, we discuss why the need for additional vertical screen space has become more important in recent years, namely, due to the transition in the marketplace of 4x3 computer screens to 16x9 and 16x10 screens (so-called widescreen format). …
This Micro Tutorial will give you a basic overview of Windows Live Photo Gallery and show you various editing filters and touches to photos you can apply. This will be demonstrated using Windows Live Photo Gallery on Windows 7 operating system.

761 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