Jump to content
Macro Express Forums

Open Excel File...Not another Instance


Recommended Posts

i have been using the Program Launch function to open an Excel File on an event. The problem is that the options are activate window (if available) or launch the program (with file location/name as a parameter). This does open the file BUT it causes another instance of Excel to open, so I have 2 instances of Excel running or however many if I continue to use this method... This is not only inefficient but it also evokes an error message for Excels personal.xls folder.

 

 

What is the best way to open a file without needing to launch another instance of a program?

 

thank you!

 

JonR

Link to comment
Share on other sites

i have been using the Program Launch function to open an Excel File on an event. The problem is that the options are activate window (if available) or launch the program (with file location/name as a parameter). This does open the file BUT it causes another instance of Excel to open, so I have 2 instances of Excel running or however many if I continue to use this method... This is not only inefficient but it also evokes an error message for Excels personal.xls folder.

 

What is the best way to open a file without needing to launch another instance of a program?

You don't say which version of Excel you're using. Excel's behaviour appears to have changed in recent versions (e.g. Excel 2007), so that double-clicking on an Excel file causes a new instance of Excel to load, even when Excel is already open.

 

Below is a description of a macro to launch and activate Excel if it's not already running, or to use Excel's Open File dialog to open the desired file if it is.

 

Here's how to solve the problem, assuming that the Excel file you want to open is stored in %tExcelFile%:

If Program "EXCEL.EXE" is running
 Window Activate: Microsoft Excel
 Text Type (Simulate Keystrokes): <CONTROL>o	 -- opens the Open File dialog
 Delay: 500 milliseconds
 Text Type (Simulate Keystrokes): %tExcelFile%<ENTER>
Else
 Launch Program and Activate Window: Program "EXCEL.EXE", Parameters "%tExcelFile%", Window "Microsoft Excel"
End If

Link to comment
Share on other sites

thank you for the code, it does work....

 

I am running Excel 2007. When I have Excel opened and I double click the file, it opens the file and not another instance of Excel..

 

ME does not have a open file function (kinda of hard to believe, computers are file systems)... So the only option is to launch a program, which is exactly what ME does to open a file...launches another instance of a program, very inefficient on many levels...

 

 

if someone has another option of opening a file, please let me know. Though the code above works i dont like that it relies on keystrokes to handle this task

 

 

thanks for the replies

 

JR

Link to comment
Share on other sites

As Paul pointed out, the "instances" of an application is dependent on the application. Some applications only allow one instance, others many. If you only want one instance, sort it out with the application or use another application that suits. "Text Type" and keystrokes are at the heart of ME and work fine. To a certain extent, the apparent crudity of ME is what makes it work in most situations and easy to use.

Link to comment
Share on other sites

thank you for the code, it does work....

 

I am running Excel 2007. When I have Excel opened and I double click the file, it opens the file and not another instance of Excel..

 

ME does not have a open file function (kinda of hard to believe, computers are file systems)... So the only option is to launch a program, which is exactly what ME does to open a file...launches another instance of a program, very inefficient on many levels...

 

 

if someone has another option of opening a file, please let me know. Though the code above works i dont like that it relies on keystrokes to handle this task

 

 

thanks for the replies

 

JR

 

Yes, it's an odd ommission from the command list IMO. Had me puzzled when I started. But in practice you simply use the Program Launch command with a file specified.

 

post-1217-1268642284_thumb.jpg

 

--

Terry, East Grinstead, UK

Link to comment
Share on other sites

Thank you for all the responses..

 

 

again, when i double-click the file and i have excel already open then it just opens the file and NOT another instance of the program. So it is not excel itself that chooses to open another application when someone opens a file to be open. the issue is that ME doesnt open a file, it launches an application again... Excel is doing exactly what is being asked, "launch program: excel.exe with parameters c:\myfilename.xls", a ME should be able to handle a simple "open file" function and not use the "launch program" function.

Link to comment
Share on other sites

I stand corrected,

 

 

i assumed you needed to add both parameters; program to launch and file location\name. which basically does what its told...

 

as terry pointed out you can just place the location\filename into the Program to Launch criteria which WILL launch the file and not the program (if already opened) sorry to jumping to my second conclusion and thank you for the replies!

 

 

MTS

Link to comment
Share on other sites

again, when i double-click the file and i have excel already open then it just opens the file and NOT another instance of the program. So it is not excel itself that chooses to open another application when someone opens a file to be open. the issue is that ME doesnt open a file, it launches an application again... Excel is doing exactly what is being asked, "launch program: excel.exe with parameters c:\myfilename.xls", a ME should be able to handle a simple "open file" function and not use the "launch program" function.

On my machine (Windows 7 Professional x64), if I have Excel open using File1.xls[m], and I double-click in Explorer on File2.xls[m], then a second instance of Excel is started. If I open File2.xls[m] from a command prompt, exactly the same behaviour occurs.

In fact, if you do a Google search on

excel open instance

you will find many topics describing exactly the problem you experienced, where a second instance of Excel is always opened.

 

So I don't understand how you manage to open a second .xls(m) file in the original instance of Excel.

 

Just to clear this up completely, if I run a Macro that opens text files in my editor of choice (UtraEdit), then only a single instance of UltraEdit is run (as defined in my UltraEdit preferences).

Link to comment
Share on other sites

Paul,

 

Here in Excel 2000 new files open in the same instance. So, it might be dependent on the version, as you and John mentioned up-thread, or it might be down to the detail entry in Tools > Folder Options > File Types > XLS > Advanced > Open > Edit

 

Here's mine (under XP Pro 32-bit). I was surprised to see that '/e' where I'm used to seeing "%1" or /dde. Mind you, I've always found Windows file associations highly obscure and inconsistent!

 

post-1217-1268662386_thumb.jpg

 

--

Terry, East Grinstead, UK

Link to comment
Share on other sites

Here in Excel 2000 new files open in the same instance. So, it might be dependent on the version, as you and John mentioned up-thread, or it might be down to the detail entry in Tools > Folder Options > File Types > XLS > Advanced > Open > Edit

Yes, MS, in their wisdom, changed this behaviour in Excel 2007. So what you report is correct for Excel 2000.

Link to comment
Share on other sites

I have yet to find a good guide to setting file associations, which is highly relevant to the file opening issue. I'm sure most people do what I do - browse file types to see the variations. In Windows "File Types" you do not seem to be able to edit sub-types eg htm being a sub-type of html. In Directory Opus you can edit both separately.

 

I have always had problems with new updates to Firefox changing the file association. I tried forever to correct htm/html in Windows "File Types". No matter what I entered I could not double-click on an htm file and get it to open. Most times, as soon as I unchecked DDE, it reset back again. Right-click and "Open With" worked OK. My second PC worked fine. It was only when I looked into types in Opus that it was clear that Firefox had set the Open action to "DDE Command" rather than "Run as an Application". Works a treat now, although I have to correct every Firefox update.

Link to comment
Share on other sites

I have yet to find a good guide to setting file associations, which is highly relevant to the file opening issue. I'm sure most people do what I do - browse file types to see the variations. In Windows "File Types" you do not seem to be able to edit sub-types eg htm being a sub-type of html. In Directory Opus you can edit both separately.

 

I have always had problems with new updates to Firefox changing the file association. I tried forever to correct htm/html in Windows "File Types". No matter what I entered I could not double-click on an htm file and get it to open. Most times, as soon as I unchecked DDE, it reset back again. Right-click and "Open With" worked OK. My second PC worked fine. It was only when I looked into types in Opus that it was clear that Firefox had set the Open action to "DDE Command" rather than "Run as an Application". Works a treat now, although I have to correct every Firefox update.

I suggest you export the relevant Firefox keys in the registry to a .reg file which you can then simply double-click to add back into the registry when a new version arrives.

 

As far as File Associations are concerned, you've got a real treat in store for you when you migrate to Windows 7. Many of the things you could do fairly easily in XP (e.g. all that horrid DDE stuff) appear to have disappeared from W7, though there are some 3rd party utilities that can help in this regard.

Link to comment
Share on other sites

The switches for associations I can find no guide on the Net. All the guides I've found state the obvious and don't get into switches. For someone like mtomas looking for specifics I suspect they are on their own There's a plethora of variations depending on the file type and usage. The one terrypin mentioned "/e" I've never seen before. Whether W7 is any better by removing the "adjustability" I'll have to leave to those with it.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...