Solved

Detect an application instance.

Posted on 2010-08-17
7
406 Views
Last Modified: 2012-05-10
We currently have a simple batch file which when kicked off by the user opens an Excel spreadsheet in a new instance of Excel. The user requirement is to open that file in an existing instance of Excel (it makes it easier for users to copu/paste from one to the other).

Can this be done from a batch file, or do we need to switch a VBScript?
0
Comment
Question by:leonstryker
[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
  • 3
7 Comments
 
LVL 5

Expert Comment

by:ploftin
ID: 33457296
I would suggest you switch to VBScript.  It is much more powerful and will do what you need.
0
 
LVL 29

Author Comment

by:leonstryker
ID: 33457476
I know it can be done easialy in VBScript, but would prefer a strictly batch solution to maintain current setup.
0
 
LVL 16

Expert Comment

by:t0t0
ID: 33458829
As far as i'm aware, if you start excel.exe with the command line option /e then invoke a file, followed by another file, both files will open in the single instance of excel.

I have actually tried this in Excel 2007 without the /e command line switch and it still works.

1) have your batch file open an instance of excel by specifying it's full path including the /e switch - something like this:

   "%programfiles%\microsoft office\office12\EXCEL.EXE /E"

2) then open your first excel document by reference (let's say it's called ACCOUNTS.XLS) - something like this:

   "%userprofile%\my documents\accounts\ACCOUNTS.XLS"

3) Now open your second excel document (let's say it's called OLDACC.XLS) - something like this:

   "%userprofile%\my documents\accounts\OLDACC.XLS"

Both XLS documents are now open in a single instance of Excel. You can verify this with the TASKLIST command. It only shows one instance of EXCEL.EXE running.

Putting this all together then, you might have something like this:


   @echo off
   set myfiles=%userprofile%\my documents\accounts

   "%programfiles%\microsoft office\office12\excel.exe /e"

   "%myfiles%\accounts.xls"
   "%myfiles%\oldacc.xls"


This will:

   1) open excel with the /e command line switch.
   2) set a variable (myfiles) to the path of my xls documents
   3) open accounts.xls file
   4) open oldacc.xls file

a simple check with TASKLIST will reveal just one instance of EXCEL.EXE running.




0
On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

 
LVL 29

Author Comment

by:leonstryker
ID: 33458934
The problem is that the user will likely has an instance of Excel running before the batch starts executing, so doing:
"%programfiles%\microsoft office\office12\excel.exe /e"
would open an additional instance. Not running it we are fine except then the user does not have an instance of Excel open in which case the batch will fail.
Leon
0
 
LVL 16

Accepted Solution

by:
t0t0 earned 500 total points
ID: 33459614
That's not a problem.... Try the rest of the code for now and see if that does the trick...

Alternatively, where the user opens his excel (most likely by clicking a shortcut link to it) edit the shortcut's properites to include the '/e' switch on the command line. At that point, you could also add additional switches including the documents' working folders (always handy) as well as specifying the working directory in the shortcut too.

So for now, leave out the following line

   "%programfiles%\microsoft office\office12\excel.exe /e"

and try opening files by referencing just the files themselves.
0
 
LVL 29

Author Closing Comment

by:leonstryker
ID: 33477400
Just leaving the file without Excel.exe and putting the /e switch after it did the trick. Thank you.
0
 
LVL 16

Expert Comment

by:t0t0
ID: 33478275
oh great stuff. well done. and thank you.
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

If like me you are one who spends a lot of time working and scripting with cmd.exe, sometimes it is handy to be able to quickly view a calendar for a given month and year. This script will quickly do just that!  Save the code posted below to a .bat …
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

617 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