How can I store the data of an open excel workbook in a collection using BluePrism? - blueprism

I open an Excel workbook with a click on a button in another program which works pretty fine. Now I would like to store the data of the workbook in a collection without saving the excel file. The name of the workbook changes dynamically. How can I save the data of the workbook in a collection?
I've already tried to use an Action stage with the Excel VBO Business Object and 'Get Worksheet as Collection' Action but as I don't know what to enter as a Workbook name nothing happens.

To do what you want is like this:
The MS Excel VBO action "Attach" will attach to whatever instance of Excel you happen to be running, regardless of any workbook names. It will output the "handle" data item that you can then use with the "Get Worksheet as Collection" action.
So this way you don't need to save the file. However, be aware that this will not work if you have more than one instance of Excel running.

Related

How to open specific excel file from Blue Prism?

I recently got an assignment to create a robot in Blue Prism and I came to a problem.
I need to open a specific excel file and work whit it.
My application modeller is set to windows application, launched from an exe file. I can launch excel without any problems but when I'm using "Action->Buissnes Object(MS Excel VBO)->Open Workbook", nothing happens.
Xlsx is not opening.
If I go whit "Open Workbook" and after that "Get Worksheet as Collection" it actualy pulls data from a file to my collection, but again its not opening the file on screen.
What I'm doing wrong?
Should I create/open instances before?
How do they work?
To work with the Excel process you SHOULD use MS Excel VBO object. The sequence of Actions to Read an Excel file is as follows:
Create Instance: To start a session of Excel. It basically creates/open a blank Excel file.
Open Workbook: To open the required Excel file.
Show: To view the Excel file (it’s invisible by default). This steps in OPTIONAL.
Get Worksheet As Collection (Fast): To read the Excel file data and store it in a collection.
Close Instance: To gracefully close the Excel Instance.
First, in your object studio, you need to use action with "Open Workbook" object using MS Excel VBO. Next step will be another action with "SHOW" object from MS Excel VBO.
With first action, BP will open workbook, but it wont be visible on the screen all the data from that workbook will be available. Second action will actually show that workbook on your screen.
you can use show action from MS Excel VBO if you want to show your excel on screen. Open Workbook and get worksheet as collection is better way to get data from excel.
In MS Excel VBO one property available "Get worksheet name" select that option under the options 'get work sheet position' you can give worksheet position.for example u want to opened 3 sheet ,u will give 3.
To work with excel you should use Excel VBO and don't have to launch by defining application moduller.
Below actions from MS Excel VBO should work.
create instance
Open workbook
Show

Assigning a variable to a spreadsheet open by a third party software

I am running into issue pulling data from a workbook that is open via SAP. The macro runs and executes multiple things in SAP and then opens the required data. The data is opened by opening an Excel window. What I am currently doing, is I assign a variable for that workbook. And use that reference throughout the entire macro.
Dim SAP_WB as workbook
'macro works within SAP and results in a workbook that pops up on the screen
Set SAP_WB=ActiveWorkbook
'macro manipulates the opened workbook and gets specific data.
That workbook is assigned to the first excel instance. The macro works great if the user has the excel tool with macros opened on the first instance as well. But if the user has multiple instances open, that is when the ActiveWorkbook does not apply. The workbook that is open from SAP has a dynamic name that I have no control over. Is there anyway to assign a variable to that workbook even though it is on another instance?

Export data back to existing csv file

I have created an application already in excel where one sheet (Sheet 1) acts as a database that stores data for thousands of records. Another sheet (Sheet 2) acts as a form where users selects a record > the form gets populated with data from Sheet 1 > user updates fields > and then save it back to Sheet 1.
This has been working great, except now we need to be able to have multiple users working in the same worksheet making updates at the same time. I cannot use the Excel Share Workbook functionality because many parts of my VBA code require unprotecting and reprotecting certain sheets and that functionality doesn't work on shared workbooks.
So now, I have split the workbook into two separate workbooks. Workbook 1 has the data in it and is saved as a .csv file. Workbook 2 is just a form that has a connection to workbook 1 via the get External Data functionality already in Excel. I can import data from the .csv file without a problem, but the only way I am finding to export the data back into the .csv file is through doing a save as. This causes a problem because it turns my multi-sheet macro enabled workbook into a csv file after the save.
Is there any other way I can update the csv file without saving my workbook as a .csv?
I don't need any code done, I just need ideas more than anything. This is already a fairly large application and due to security restrictions I have already been told I cannot use a SQL server connection and we do not have access to Access to use an Access database. So solution has to stay inside excel/text files?

How to get value within an Excel workbook in Sharpoint into Active workbook

I have an excel workbook that needs to get data from an excel workbook hosted in a Sharepoint document library. Creating a list from the source file is not an option :/
I am able to open the source excel file but I don't want the user to see it opening.
Surprisingly simple.
Application.ScreenUpdating = False
Was also thinking it would be a performance issue creating a whole workbook process but works without a hitch.

Creating multiple worksheets in Excel using X++

I am currently able to create a new Excel spreadsheet, write to it and save the spreadsheet through X++.
I have a few methods within a new class, each intended to write to a separate worksheet within the workbook.
The first method creates the spreadsheet, writes the data, saves the spreadsheet, and then quits Excel just fine. But within the next method I attempt to open the saved spreadsheet, write to another worksheet (tab), save again, and quit Excel.
The second method causes the following error.
Method 'saveAs' in COM object of class '_Workbook' returned error code 0x800A03EC () which means: You cannot save this workbook with the same name as another open workbook or add-in. Choose a different name, or close the other workbook or add-in before saving.
Is it possible to create and save multiple Excel worksheets within one Excel workbook in X++?
Thanks again to Jan for responsing
After reviewing the SysDataExcelCOM class, there is a CreateWorkbook method which creates the additional worksheets for the Excel Data Definition export. After creating a new similar class method and also declaring my own set of defined names (#define.ExampleExcelWorksheetName('abcSheet') for the Excel Worksheets, I was then able to create the Excel Workbook with multiple worksheets. Then save (SysExcelWorkbook.saveAs) after all of the necessary sheets are created first, rather than open the saved Workboook then adding worksheets per new class method.
Within the other class methods where data is intended to write to the Worksheets, I opened the Workbook created by the new method similar to CreateWorkbook (sysExcelWorkbooks.open(yourExcelFile), then refer to each Worksheet using (sysExcelWorksheet.itemByName) to write the data to the specific Worksheet, then save.
excelApplication = SysExcelApplication::construct();
excelWorkbooks = excelApplication.workbooks();
excelWorkbooks.open(fileNameSave);
excelWorkbook = excelWorkbooks.item(1);
//Add styles and fonts
excelStyles = excelWorkbook.styles();
excelStyle = excelStyles.add("Header");
excelFont = excelStyle.font();
excelFont.bold(true);
excelWorksheets = excelWorkbook.worksheets();
excelWorksheet = excelWorksheets.itemFromName(#declared name of your worksheet);
// Begin Header Row
excelWorksheet.cells().item(1,1).value("value of your choice");
excelWorksheet.cells().item(1,2).value("value of your choice");
excelWorksheet.rows().item(1).style("Header");
excelWorksheet.name("Rename your declared worksheet name or use current name here");
excelCells = excelWorksheet.cells();
excelCells.range('A:B').numberFormat('#');
//Find you data to write to Excel Worksheet here
excelWorksheet.columns().autoFit();
excelApplication.displayAlerts(false);
excelWorkbook.saveAs(fileNameSave);
excelWorkbook.comObject().save();
excelWorkbook.saved(true);
excelApplication.quit();
Going this route worked well for me.
This is maybe not a direct answer to your question, but might give you another perspective on creating Excel files.
I tend to use XML and XSLT to create Excel files. You can easily create what you want in Excel and then save the Excel file as XML and then you can apply some XSLT that reads data from another XML file and puts it into the Excel file you want.
You can find a post concerning this topic on my blog : Using C#, XML and XSLT to create Excel files
There I create an XML file containing Items and transform that into an Excel file.
Check the idendity of the Excel COM service. See what others have done.

Resources