Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
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
Medium Priority
?
376 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:
Frank White earned 900 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

The recent Microsoft changes on update philosophy for Windows pre-10 and their impact on existing WSUS implementations.
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…
Windows 8 comes with a dramatically different user interface known as Metro. Notably missing from the new interface is a Start button and Start Menu. Many users do not like it, much preferring the interface of earlier versions — Windows 7, Windows X…
This Micro Tutorial will teach you how to the overview of Microsoft Security Essentials. This is a free anti-virus software that guards your PC against viruses, spyware, worms, and other malicious software. This will be demonstrated using Windows…
Suggested Courses

719 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