Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default More about trying to automation multiple Excel instances

Hello,

There were already posts about impossibility to automate multiple Excel
instances (only first started instance is automated). But, actually, it's
vital for product we develop. So, I still don't lose hope :)

First question.
As I understand, functions which are used to obtain running Excel instance
(Marshal.GetActiveObject in .Net or GetObject in VBScript) look for it in the
Running Object Table (ROT). So, what is the main point - only first Excel
instance is registered in ROT? or thay all are registered, but the first is
returned? If all Excel instances are registered, can we use
IRunningObjectTable::EnumRunning method to enum them and bind to each of them?

Second question.
Can we at least ajust somehow Excel behavior (using its own settings) for it
to start as single instance (like Word)?

Thank you in advance!

--
Best Regards,
Sergei Emelyanenkov

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 118
Default More about trying to automation multiple Excel instances

Good afternoon, Sergei. Welcome to Microsoft Newsgroup Support Service! My
name is Jialiang Ge [MSFT]. It's my pleasure to work with you in this issue.

According to the post, you wonder how to automate a specific instance of
Excel. As far as I know, there are at least two ways that meet the
requirement. Sergei, you mentioned the "impossibility to automate multiple
Excel Instances". Would you mind sharing me with these posts? There might
be some special limits that I am not aware of. Thanks.

For your first question, all the Excel instances are registered in ROT
(Running Object Table). The instance that is first registered in the ROT is
typically the instance that is returned by GetActiveObject. If you want to
get an Automation Reference to a specific running instance of Word, Excel,
or Microsoft Access, we can consider
Method 1. use BindToMoniker with the name of the file that is opened in
that instance.
- or -
Method 2. IRunningObjectTable::EnumRunning

Please allow me to demonstrate these two methods one by one:

*Method 1. Use BindToMoniker with the name of the file that is opened in
that instance.*
There is a very good KB article that provides examples of BindToMoniker for
Office and explains the Multiuse and Singe Use mechanisms of Office
products to help you have a clearer picture of COM and ROT:

How to use Visual C# to automate a running instance of an Office program
http://support.microsoft.com/kb/316126

I also write a code snippet for your reference:
(Suppose two instances of excel.exe have loaded Book1.xls and Book2.xls
repectively)
The code sets a value to the workbooks in different instances of Excel.

[STAThread] //STA thread declaration is necessary.
static void Main(string[] args)
{
Excel.Workbook xlwkbook1, xlwkbook2;
Excel.Worksheet xlsheet1, xlsheet2;

//Get a reference to the Workbook object by using a file
moniker.
//The xls was saved earlier with this file name.
xlwkbook1 =
(Excel.Workbook)Marshal.BindToMoniker(@"D:\Test\Bo ok1.xls");
xlwkbook2 =
(Excel.Workbook)Marshal.BindToMoniker(@"D:\Test\Bo ok2.xls");

xlsheet1 = (Excel.Worksheet)xlwkbook1.ActiveSheet;
xlsheet1.Cells[1, 1] = 111;

xlsheet2 = (Excel.Worksheet)xlwkbook2.ActiveSheet;
xlsheet2.Cells[1, 1] = 222;
}

For more readings about moniker, I recommend the book "Essential COM" by
DON BOX. In its Chapter 3, "Classes", Moniker is introduced in detail.

*Method 2. IRunningObjectTable::EnumRunning*
I searched online, and also found a very good article for EnumRunning.
Although the article is for "automating a specific instance of Visual
Studio.net", the principle is the same for Office.
http://www.codeproject.com/KB/cs/aut...ualstudio.aspx
If you encounter any problem when converting its code to the use of Office,
please don't hesitate to let me know.

For your second question:
"Can we at least adjust somehow Excel behavior (using its own settings) for
it to start as single instance (like Word)?"

According to the KB article http://support.microsoft.com/kb/316126, Excel
is designed as a Single Use (Multiple Instances) server:
<quote
Multiple instances of Word (Winword.exe), Excel (Excel.exe), and Microsoft
Access (MSAccess.exe) can run simultaneously. Therefore, these servers are
defined as Single Use (Multiple Instances) servers. Only one instance of
PowerPoint (Powerpnt.exe) can run at any given time. Therefore, PowerPoint
is a Multiuse (Single Instance) server.
</quote
Therefore, as far as I know, there is no option to allow only one instance
of Excel in the machine. Even for Word, we are still able to create
multiple winword.exe instances by calling CreateObject("Word.Application")
for serveral times. Sergei, I will confirm this point with the product team
and get to you soon.

Please let me know if you have any other concerns, or need anything else.

Regards,
Jialiang Ge , remove 'online.')
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
.

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default More about trying to automation multiple Excel instances

Hello Jialiang, thank you for your quick response!

I think, Method 2. is a right direction to solve my problem. Let me try to
implement it and I reply again.

Conserning "impossibility to automate multiple Excel Instances" - my be I
have overstaded it a little :) Actually, I found only one post in this
newsgroup with subject "GetActiveObject("Excel.Application") for multiple
instances of Exc" (posted 6/18/2008). There was only one unfavourable reply
"If GetActiveObject works like GetObject() then I don't think there's any way
to get a specific instance of an application".

--
Best Regards,
Sergei Emelyanenkov



""Jialiang Ge [MSFT]"" wrote:

Good afternoon, Sergei. Welcome to Microsoft Newsgroup Support Service! My
name is Jialiang Ge [MSFT]. It's my pleasure to work with you in this issue.

According to the post, you wonder how to automate a specific instance of
Excel. As far as I know, there are at least two ways that meet the
requirement. Sergei, you mentioned the "impossibility to automate multiple
Excel Instances". Would you mind sharing me with these posts? There might
be some special limits that I am not aware of. Thanks.

For your first question, all the Excel instances are registered in ROT
(Running Object Table). The instance that is first registered in the ROT is
typically the instance that is returned by GetActiveObject. If you want to
get an Automation Reference to a specific running instance of Word, Excel,
or Microsoft Access, we can consider
Method 1. use BindToMoniker with the name of the file that is opened in
that instance.
- or -
Method 2. IRunningObjectTable::EnumRunning

Please allow me to demonstrate these two methods one by one:

*Method 1. Use BindToMoniker with the name of the file that is opened in
that instance.*
There is a very good KB article that provides examples of BindToMoniker for
Office and explains the Multiuse and Singe Use mechanisms of Office
products to help you have a clearer picture of COM and ROT:

How to use Visual C# to automate a running instance of an Office program
http://support.microsoft.com/kb/316126

I also write a code snippet for your reference:
(Suppose two instances of excel.exe have loaded Book1.xls and Book2.xls
repectively)
The code sets a value to the workbooks in different instances of Excel.

[STAThread] //STA thread declaration is necessary.
static void Main(string[] args)
{
Excel.Workbook xlwkbook1, xlwkbook2;
Excel.Worksheet xlsheet1, xlsheet2;

//Get a reference to the Workbook object by using a file
moniker.
//The xls was saved earlier with this file name.
xlwkbook1 =
(Excel.Workbook)Marshal.BindToMoniker(@"D:\Test\Bo ok1.xls");
xlwkbook2 =
(Excel.Workbook)Marshal.BindToMoniker(@"D:\Test\Bo ok2.xls");

xlsheet1 = (Excel.Worksheet)xlwkbook1.ActiveSheet;
xlsheet1.Cells[1, 1] = 111;

xlsheet2 = (Excel.Worksheet)xlwkbook2.ActiveSheet;
xlsheet2.Cells[1, 1] = 222;
}

For more readings about moniker, I recommend the book "Essential COM" by
DON BOX. In its Chapter 3, "Classes", Moniker is introduced in detail.

*Method 2. IRunningObjectTable::EnumRunning*
I searched online, and also found a very good article for EnumRunning.
Although the article is for "automating a specific instance of Visual
Studio.net", the principle is the same for Office.
http://www.codeproject.com/KB/cs/aut...ualstudio.aspx
If you encounter any problem when converting its code to the use of Office,
please don't hesitate to let me know.

For your second question:
"Can we at least adjust somehow Excel behavior (using its own settings) for
it to start as single instance (like Word)?"

According to the KB article http://support.microsoft.com/kb/316126, Excel
is designed as a Single Use (Multiple Instances) server:
<quote
Multiple instances of Word (Winword.exe), Excel (Excel.exe), and Microsoft
Access (MSAccess.exe) can run simultaneously. Therefore, these servers are
defined as Single Use (Multiple Instances) servers. Only one instance of
PowerPoint (Powerpnt.exe) can run at any given time. Therefore, PowerPoint
is a Multiuse (Single Instance) server.
</quote
Therefore, as far as I know, there is no option to allow only one instance
of Excel in the machine. Even for Word, we are still able to create
multiple winword.exe instances by calling CreateObject("Word.Application")
for serveral times. Sergei, I will confirm this point with the product team
and get to you soon.

Please let me know if you have any other concerns, or need anything else.

Regards,
Jialiang Ge , remove 'online.')
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
.

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default More about trying to automation multiple Excel instances

So, I've carried out an investigation based on
http://www.codeproject.com/KB/cs/aut...ualstudio.aspx
to discover how Excel is registered in ROT. Here is the summary:

Excel registers itself in ROT as item moniker with display name
"!{00024500-0000-0000-C000-000000000046}". Number of such monikers equals to
the number of Excel processes. BUT, comparing this monikers among themselves
using IMoniker.IsEqual returns S_OK! And receiving the instance of
Excel.Application from any of them gives again first started Excel instance.
It is confusing, but there is a workaround described below.

All opened Excel workbooks are registered in ROT as file monikers with
theirs full names as display names. Receiving Workbook object from these
monikers works fine. Application property of Workbook object gives us
Excel.Application object, corresponding to the Workbook's owner process. In
this way we can recive all Excel instances (at least :).

This results are good enaugh for me to solve my problems.

Jialiang, thank you again for your help!

--
Best Regards,
Sergei Emelyanenkov



"Sergei Emelyanenkov" wrote:

Hello Jialiang, thank you for your quick response!

I think, Method 2. is a right direction to solve my problem. Let me try to
implement it and I reply again.

Conserning "impossibility to automate multiple Excel Instances" - my be I
have overstaded it a little :) Actually, I found only one post in this
newsgroup with subject "GetActiveObject("Excel.Application") for multiple
instances of Exc" (posted 6/18/2008). There was only one unfavourable reply
"If GetActiveObject works like GetObject() then I don't think there's any way
to get a specific instance of an application".

--
Best Regards,
Sergei Emelyanenkov



""Jialiang Ge [MSFT]"" wrote:

Good afternoon, Sergei. Welcome to Microsoft Newsgroup Support Service! My
name is Jialiang Ge [MSFT]. It's my pleasure to work with you in this issue.

According to the post, you wonder how to automate a specific instance of
Excel. As far as I know, there are at least two ways that meet the
requirement. Sergei, you mentioned the "impossibility to automate multiple
Excel Instances". Would you mind sharing me with these posts? There might
be some special limits that I am not aware of. Thanks.

For your first question, all the Excel instances are registered in ROT
(Running Object Table). The instance that is first registered in the ROT is
typically the instance that is returned by GetActiveObject. If you want to
get an Automation Reference to a specific running instance of Word, Excel,
or Microsoft Access, we can consider
Method 1. use BindToMoniker with the name of the file that is opened in
that instance.
- or -
Method 2. IRunningObjectTable::EnumRunning

Please allow me to demonstrate these two methods one by one:

*Method 1. Use BindToMoniker with the name of the file that is opened in
that instance.*
There is a very good KB article that provides examples of BindToMoniker for
Office and explains the Multiuse and Singe Use mechanisms of Office
products to help you have a clearer picture of COM and ROT:

How to use Visual C# to automate a running instance of an Office program
http://support.microsoft.com/kb/316126

I also write a code snippet for your reference:
(Suppose two instances of excel.exe have loaded Book1.xls and Book2.xls
repectively)
The code sets a value to the workbooks in different instances of Excel.

[STAThread] //STA thread declaration is necessary.
static void Main(string[] args)
{
Excel.Workbook xlwkbook1, xlwkbook2;
Excel.Worksheet xlsheet1, xlsheet2;

//Get a reference to the Workbook object by using a file
moniker.
//The xls was saved earlier with this file name.
xlwkbook1 =
(Excel.Workbook)Marshal.BindToMoniker(@"D:\Test\Bo ok1.xls");
xlwkbook2 =
(Excel.Workbook)Marshal.BindToMoniker(@"D:\Test\Bo ok2.xls");

xlsheet1 = (Excel.Worksheet)xlwkbook1.ActiveSheet;
xlsheet1.Cells[1, 1] = 111;

xlsheet2 = (Excel.Worksheet)xlwkbook2.ActiveSheet;
xlsheet2.Cells[1, 1] = 222;
}

For more readings about moniker, I recommend the book "Essential COM" by
DON BOX. In its Chapter 3, "Classes", Moniker is introduced in detail.

*Method 2. IRunningObjectTable::EnumRunning*
I searched online, and also found a very good article for EnumRunning.
Although the article is for "automating a specific instance of Visual
Studio.net", the principle is the same for Office.
http://www.codeproject.com/KB/cs/aut...ualstudio.aspx
If you encounter any problem when converting its code to the use of Office,
please don't hesitate to let me know.

For your second question:
"Can we at least adjust somehow Excel behavior (using its own settings) for
it to start as single instance (like Word)?"

According to the KB article http://support.microsoft.com/kb/316126, Excel
is designed as a Single Use (Multiple Instances) server:
<quote
Multiple instances of Word (Winword.exe), Excel (Excel.exe), and Microsoft
Access (MSAccess.exe) can run simultaneously. Therefore, these servers are
defined as Single Use (Multiple Instances) servers. Only one instance of
PowerPoint (Powerpnt.exe) can run at any given time. Therefore, PowerPoint
is a Multiuse (Single Instance) server.
</quote
Therefore, as far as I know, there is no option to allow only one instance
of Excel in the machine. Even for Word, we are still able to create
multiple winword.exe instances by calling CreateObject("Word.Application")
for serveral times. Sergei, I will confirm this point with the product team
and get to you soon.

Please let me know if you have any other concerns, or need anything else.

Regards,
Jialiang Ge , remove 'online.')
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
.

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 118
Default More about trying to automation multiple Excel instances

Good morning, Sergei. Thank you for this great summary. According to the
test results, the only solution to automate multiple Excel instances seems
to be "file moniker", which was also mentioned in the "method 1" of my
initial reply, and was demonstrated in the KB article: How to get IDispatch
of an Excel or Word document from an OCX.
http://support.microsoft.com/kb/q190985/

Sergei, if you want to dig out the reason for the failure of "item moniker"
("!{00024500-0000-0000-C000-000000000046}".), I'm very willing to help. In
fact, I'm also interested in the product team's consideration behind this
design. My researches so far are at the bottom of this message. Though the
reason has not been found out, I am going to discuss it with the Excel
designers directly.

--------------------------------------------------
My researches so far:

I start two instances of Excel, open two workbooks (Book1.xls, Book2.xls)
respectively. In order to see the current ROT status visually, I use the
tool "ROT Viewer" shipped with VC6. ROT Viewer lists the following monikers
related to Excel:

{!00024500-0000-0000-C000-000000000046}
{!00024500-0000-0000-C000-000000000046}
D:\test\book1.xls
D:\test\book2.xls

where the first two are item monikers and the rest are file monikers. From
ROT Viewer, I also see the item monikers have the same properties, e.g.
Hash Value. To verify whether they indeed refer to the same instance, I
wrote a small program to enumrunnings, cast them to Excel.Application, and
as you found out, the automation code run on these Excel.Application
objects only happens to the first instance of Excel. That's to say, the two
instances refer to the same instance of Excel.

I'm holding further discussions with my colleagues, and I promise to be
back soon.

Regards,
Jialiang Ge , remove 'online.')
Microsoft Online Community Support

=================================================
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
.

This posting is provided "AS IS" with no warranties, and confers no rights.
=================================================



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default More about trying to automation multiple Excel instances

Hello Jialiang,
of course, it's interesting for me to know why Ecxel behave in this manner! :)

Waiting impatiently for the results of your investigations.
--
Best Regards,
Sergei Emelyanenkov
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I isolate my Excel server (automation) from other Excel instances? Joseph Geretz Excel Discussion (Misc queries) 5 July 19th 13 03:18 PM
Multiple instances of Excel (Multiple workbooks) Shane Setting up and Configuration of Excel 3 November 13th 09 05:07 PM
Using RTD with multiple instances of excel [email protected] Excel Discussion (Misc queries) 0 February 13th 09 10:51 AM
Multiple Instances of EXCEL.EXE MKG Excel Discussion (Misc queries) 3 February 3rd 07 12:08 AM
Multiple instances of Excel and VB Rich[_16_] Excel Programming 2 September 19th 03 07:59 AM


All times are GMT +1. The time now is 10:38 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"