How do i open a new instance Excel?

G

Guest

How do I open excel workbook in its own instance of Excel. When I have Excel
running and open another Excel workbook file (with an .xls extension) it is
opened in the instance I have running. So, when I exit Excel both workbooks
are closed. This is a problem when for a program that has a hidden Excel
workbook running. If I start another Excel file, it uses the instance of
Excel the program is using. This causes a problem for the program because I
shows the hidden file and will close it if the instance is closed. If I open
an instance of Excel then load the file, I get new instance of Excel. Is
there a way to tell the system to open a new Excel file in a new instance?
 
F

Fred

Micheal try,

Dim xlApp as Excel.Application
set xlApp = CreateObject("Excel.Application")
xlApp.Visible = True
xlApp.Workbooks.Open FileName:="C:\Book1.xls"


Fred
 
W

William Benson

Any idea why this opens an instance without the message that certain
workbooks are already locked for editing (e.g., Personal.XLS)?

(typically a
 
N

Norman Jones

William Benson said:
Any idea why this opens an instance without the message that certain
workbooks are already locked for editing (e.g., Personal.XLS)?


The code ONLY loads the designated workbook (Book1.xls). AddIns and files in
the XLStart folder, such as Personal.xls, do not get loaded.Consequently,
the question of locked files does not arise.

Hit Alt-F11 and look at the files in the VBE.
 
W

William Benson

I see. As an interesting side note, but in keeping with my original question
(you answered why Personal doesn't open, but missed the heart of my concern)
it opens any unopen file without warnings about read-only (or macros, for
that matter). In fact, if the calling procedure is from a file with macros
enabled, you will not be asked if you want the called file to be opened with
or without macros.

This produced an interesting (please don't try this with any other apps
running and I suggest saving all your work cuz ya gonna need to shut down
the HARD WAY) effect: I put Fred's code into the Workbook_Open sub of the
file Book1 on C: and it called itself recursively when opened ... I was
given only one chance to say Yes/No to macros, then BOOM.

I repeat, I wouldn't try it.

And I have learned NEVER EVER EVER say Yes to macros the first time you open
a file ... and be sure to look at ALL the code before you ever try it WITH
macros enabled.

Thanks,

Bill

Norman Jones said:
Hi William,

See also MSKB 213489:
Add-Ins Don't Load When Using the CreateObject Command

http://support.microsoft.com/default.aspx?scid=kb;en-us;213489
 
W

William Benson

It obviously opens unopen files without warnings about read-only, but what I
meant to write is it ALSO opens ALREADY OPENED files without read-only
warnings, in the new instances of Excel...

William Benson said:
I see. As an interesting side note, but in keeping with my original
question (you answered why Personal doesn't open, but missed the heart of
my concern) it opens any unopen file without warnings about read-only (or
macros, for that matter). In fact, if the calling procedure is from a file
with macros enabled, you will not be asked if you want the called file to
be opened with or without macros.

This produced an interesting (please don't try this with any other apps
running and I suggest saving all your work cuz ya gonna need to shut down
the HARD WAY) effect: I put Fred's code into the Workbook_Open sub of the
file Book1 on C: and it called itself recursively when opened ... I was
given only one chance to say Yes/No to macros, then BOOM.

I repeat, I wouldn't try it.

And I have learned NEVER EVER EVER say Yes to macros the first time you
open a file ... and be sure to look at ALL the code before you ever try it
WITH macros enabled.

Thanks,

Bill
 
T

Tushar Mehta

This addresses only the part about macro warnings. That lack of
warning is by design (and configurable). When code opens a workbook
containing macros, it is subject to the AutomationSecurity property.
The default value of that property is msoAutomationSecurityLow.

My guess is that MS decided that if you trust the code that is
currently running, you trust any code that it, the currently executing
code, chooses to invoke.

--
Regards,

Tushar Mehta
www.tushar-mehta.com
Excel, PowerPoint, and VBA add-ins, tutorials
Custom MS Office productivity solutions

wbenson1 said:
I see. As an interesting side note, but in keeping with my original question
(you answered why Personal doesn't open, but missed the heart of my concern)
it opens any unopen file without warnings about read-only (or macros, for
that matter). In fact, if the calling procedure is from a file with macros
enabled, you will not be asked if you want the called file to be opened with
or without macros.

This produced an interesting (please don't try this with any other apps
running and I suggest saving all your work cuz ya gonna need to shut down
the HARD WAY) effect: I put Fred's code into the Workbook_Open sub of the
file Book1 on C: and it called itself recursively when opened ... I was
given only one chance to say Yes/No to macros, then BOOM.

I repeat, I wouldn't try it.

And I have learned NEVER EVER EVER say Yes to macros the first time you open
a file ... and be sure to look at ALL the code before you ever try it WITH
macros enabled.

Thanks,

Bill
 
G

Guest

Using create object did not work. I may be in the wrong group but this is
what I am doing.
I am opening an Excel workbook from a VB.NET program using:
_myApplaction = New Excel.Application
_myWorkbook = ._myApplaction.Workbooks.Open(ExcelWorkbookPath)
I also tried
_myApplaction = CreateObject("Excel.Application")

_myWorkbook = ._myApplaction.Workbooks.Open(ExcelWorkbookPath)

In both cases if I open a workbook file it uses the running Excel instance
you can see this by looking at the Windows menu, both files are listed there.

If I open Excel and then open the workbook, it is in a new instance in each
instance the Windows menu will only show one workbook.
Is there a way to tell excel to open a new instance when a workbook file is
opened, preferably programmability.
 
T

Tushar Mehta

Maybe, there is some option in XL that I have long since forgotten but
if not using CreateObject is SOP for starting a new instance of XL.
Another possibility is that .Net is doing something different.

One way to narrow down the source of the problem would be to
instantiate a new copy of XL from VB or from VBA running in another
Office program or from VBA running in XL itself. If VB/A works fine
then you can safely focus your attention on the .Net interface. If it
doesn't there's something about that machine / copy of XL.

One final note. You may want to ensure you have the latest support
release for your version of XL.


--
Regards,

Tushar Mehta
www.tushar-mehta.com
Excel, PowerPoint, and VBA add-ins, tutorials
Custom MS Office productivity solutions
 
G

Guest

It has something to do with how the XP launches a file associated with an
exe. If I click on or choose, open form the context menu in the file
explorer the workbook is loaded into the most recently launched instance of
Excel or if I launch the file alone form the command line it is put into the
most recently launched instance of Excel. If I launch Excel and then load
the file I get a separate instance of Excel or if I launce excel from the
command line with the file as a command line argument I get a second instance
of excel.
I know .NET launches a new instance of Excel because I can wind up with
several running. I can verify this by the tasks manager. I will have
several Excels running that I need to explicitly end them.
A quick check of Word and Visio; Visio is similar Excel and Word is
different. Word under the Windows menu you can see all the running documents
but closing there window only closes the one document.
 
T

Tushar Mehta

OK, now I am confused. All along I thought that .Net CreateObject was
not instantiating a new copy of XL. But, in your latest post you
indicate that you are. So, what problem are you are trying to resolve?

--
Regards,

Tushar Mehta
www.tushar-mehta.com
Excel, PowerPoint, and VBA add-ins, tutorials
Custom MS Office productivity solutions
 
P

Peter Huang [MSFT]

Hi Mike,

I agree with Tushar's suggestion.
Can you so kind to describe your goal detailed?
If you want to open the xls file in a new excel.exe instance, you may try
to CreateObject and use the created instance to open the excel file.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
G

Guest

Is there a way to tell the system to open a new Excel file in a new instance?

Yes. Application.IgnoreRemoteRequests = True


Regards,
Vic Eldridge
 
G

Guest

Vic
That worked! How did you find that out? It not documented in the app
object for Excel. Infect when I look for "IgnoreRemoteRequests" in help it
did not show up. It looks like a hangover from the DDE days. I did not see
it in the intelligence scene list until you pointed it out.
Thank you,
 
P

Peter Huang [MSFT]

Hi

This is included in the excel vba help file.
<Program Files>\Microsoft Office\OFFICE11\1033\VBAXL10.CHM

IgnoreRemoteRequests Property
See AlsoApplies ToExampleSpecifics
True if remote DDE requests are ignored. Read/write Boolean.

Example
This example sets the IgnoreRemoteRequests property to True so that remote
DDE requests are ignored.

Application.IgnoreRemoteRequests = True




Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
G

Guest

Peter Thank you,
Under the “no question is a dumb question department’ can one assume that
the object model in VBA is reflected through to the .NET
Microsoft.Office.Interop.Excel?
 
P

Peter Huang [MSFT]

Hi

Yes.
Acutally the Interop.Excel.dll is an .NET wrap for the Excel.EXE COM Object
Modal.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
W

William Benson

Took me forever to get around to revisiting this thread ... but thanks for
the heads up about AutomationSecurity.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top