Solved

Detect an application instance.

Posted on 2010-08-17
7
404 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
How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
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…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

740 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