Solved How can I share an Excel instance and open workbook between processes

mbailey

Member
I'm new to Blue Prism and I'm writing a callable, shared Blue Prism process to start an Excel instance, open or create a workbook/worksheet, and allow the calling process to interact with that workbook. This will allow me to validate the directory and file names and perform all the actions and error checking without having to rewrite the same code in each of the many robots we're writing. I'm passing the Excel handle back to the caller but, when the caller attempts to interact with the spreadsheet, a "The given key was not present in the dictionary” error occurs. I speculate that, when process 1 starts an Excel instance and opens or creates a workbook, process 2 must “connect” to that Excel instance and workbook in order to interact with it. If I am correct, process 2 did not start any Excel instances so its dictionary is empty and the Excel handle being passed to it cannot be resolved.

Pages in the Excel VBO include Open Instance, Set Current Instance, Attach, and Attach to Workbook. Some of these look like they might address this problem but there is no documentation other than the brief comments in the Page Information stages. In the case I described above, there is only one Excel instance but other situations will have multiple Excel instances open. I don't want to close and reopen the workbook because that defeats the purpose of creating a callable, reusable process to handle this task. Is there a best method for sharing a specific Excel instance (with or without reference to an open workbook) between two different Blue Prism processes?
 

VJR

Well-Known Member
Hi mbailey,

Process1:
-Start Excel Instance
-open or create a Workbook/Worksheet

Process2:
-calls Process1 and work with the Workbook created/opened by Process1
- What is part that you do not want to do in Process2?

Can you elaborate more on what the below is-
"This will allow me to validate the directory and file names and perform all the actions and error checking without having to rewrite the same code in each of the many robots we're writing."
 

mbailey

Member
The process I'm writing takes parameters, including the full file path/name of the workbook to be opened or created and the name of the worksheet to be activated or created. If these parameters are invalid (no path provided, file or directory does not exist, the file extension was omitted, worksheet name is incorrect, etc), the errors that occur must be detected and handled. These filenames and other parameters are being read from documents and we discovered that they frequently contain errors. Some errors may raise an exception while others are only known by checking the Success flag and Message item returned by the Excel VBO. Some common errors such as an omitted file extension can be detected and resolved without human intervention. We have a standard error handling process for all the robots being written to log the error and, when appropriate, send an email for the error. The individual calls to Excel VBO pages to start Excel, create or open the worksheet, activate it, and create or activate the worksheet plus the error checking and handling require the same code to be written for each robot. This is what I don't want process 2 to perform. I realize that what I'm describing is more elaborate than what you describe under Process 1 but finding a way to share the Excel instance will save us a lot of code duplication.
 

mbailey

Member
Regardless of the particular circumstances, I want to know if and how an Excel instance and workbook opened by one Blue Prism process can be shared with another Blue Prism process. I am not looking for a workaround, just an answer to that specific question.
 

VJR

Well-Known Member
My observation is the same as what you have noticed that the handle is lost as Blue Prism throws the dictionary key error when the opened instance is passed from one process to another and used there.
 
Top