1

How Do control with python multiple instances of Excel. This is not read/write, but more running macros on different workbooks.

Ex: Excel.exe running Book1.xls. has mac1 Excel.exe running Book2.xls. has mac2.

I got one instance to work, this first instance, which use 2003. I could not figure out the other instance which is 2007.

If 2 can be done, can 3 or 4, Or is the a limit. I thought of memcache launching the different instances, but really not sure, if workable.

TIA

working on apply this: Using Python to program MS Office macros?

Community
  • 1
  • 1
Merlin
  • 24,552
  • 41
  • 131
  • 206
  • Ok, tried to figure this out, need more help. Created a timeprint macro in pyVBA.xls works on 1st instance, CLosed, opened in second instance, did not run see dialog box in 1st instance. here the code ##pyhton 2.6 from win32com.client import Dispatch #as comDispatch def doit(): xl = Dispatch('Excel.Application') #xl.Visible = 1 #xl.Workbooks.Open("C:\pyVBA.xls", True, True) xl.Run("C:\pyVBA.xls!Macro1") – Merlin Aug 24 '10 at 19:28

1 Answers1

1

Unfortunately you cannot control which instance you get back when grabbing things from the ROT (running object table.) Only the first instance of an application will register itself.

http://support.microsoft.com/kb/238975

However, each document is registered in the ROT so in your case you may be able to find the right instance by looking for documents.

-Oisin

x0n
  • 51,312
  • 7
  • 89
  • 111
  • Can you give me an example for the above example? thanks... for quick answer – Merlin Aug 23 '10 at 22:24
  • here's some C# to iterate through the contents of the ROT: http://www.vbusers.com/codecsharp/codeget.asp?ThreadID=69&PostID=1 - fire up two instances of excel, each with a different XLS loaded. Look in the ROT for excel.document instances (should be two), not excel.application (there will be only one) – x0n Aug 26 '10 at 03:35
  • I use python (trying,more) and VBA (trying, less) – Merlin Sep 03 '10 at 15:59