cancel
Showing results for 
Search instead for 
Did you mean: 

Pasting screen shot in Excel

Niraj.kumar
Level 2

Hello BP Experts,

I'm reaching out for guidance regarding arranging screenshots sequentially in Excel, each with specific height and width parameters.

Here's an example scenario: Navigate to a specific screen on SAP, capture the screenshot, paste it into Excel with designated height and width. Then, return to SAP, navigate to a different screen, capture another screenshot, and paste it next to the previous one in Excel.

I hope this requirement is clear. Your expertise on this matter would be invaluable. #SAP, #Excel

3 REPLIES 3

I am running into the same requirement.

Was this already resolved?

Hi @Niraj.kumar and @rey.saldua_db.com ,

Thanks for bringing this query up. It seems to have gone unanswered for quite a while so I am providing my inputs for the same.

Currently, I don't think there is any action to achieve this functionality in the current 'MS Excel - 10.3.0' VBO which has been posted in DX Exchange.

But you can achieve this functionality by extending either 'MS Excel' by creating a new action within the object.

NOTE: I would recommend create a duplicate object of these objects and make your changes there so that you always have a backup with you in case anything goes wrong.

Now, you need to create a new action in your already existing Excel VBO business object named 'Insert Image' and provide the following input parameters to your action:

handle: This is a number type data item which will hold the current session dictionary value.

workbookname : This is a text type data item where you need to pass the workbook name that you might get from 'Create Workbook' or 'Open Workbook' action.

worksheetname: This is a text type data item which indicates the name of the worksheet in your excel workbook file where you want to insert the image.


cellref: This is a text type data item which indicates the name of the worksheet in your excel workbook file where you want to insert the image.

imagefilepath: This is a text type data item which indicates the file path of the image that needs to be inserted.

imageheight: This is a number type data item which indicates the height dimension of the image to be inserted.

imagewidth: This is a number type data item which indicates the width dimension of the image to be inserted.

 

devneetmohanty07_0-1717430800857.png

 

Now, you can add a page reference stage to the 'Activate Sheet' page and then add another code stage named 'Insert Image' and add the following inputs parameter and map the data items to it:

devneetmohanty07_1-1717430905985.png

devneetmohanty07_2-1717430964658.png

Add the following code under the Code tab:

 

Try

    Dim worksheet As Object = GetWorksheet(handle, workbookname, worksheetname)
    
    ' Get the range for the cell reference
    Dim cell As Object = worksheet.Range(cellref)
    
    ' Get the left and top position of the cell
    Dim left As Double = cell.Left
    Dim top As Double = cell.Top
    
    ' Add the picture to the worksheet
    Dim pictures As Object = worksheet.Pictures
    Dim pic As Object = pictures.Insert(imagefilepath)
    
    ' Set the picture properties
    pic.Left = left
    pic.Top = top
    pic.Width = imagewidth
    pic.Height = imageheight
    
    ' Clean up
    ReleaseObject(pic)
    ReleaseObject(pictures)
    ReleaseObject(cell)
    ReleaseObject(worksheet)

Catch ex As Exception

    ' Handle any exceptions
    Throw New Exception("Error pasting screenshot: " & ex.Message)

End Try

 

devneetmohanty07_3-1717431108800.png

 

You should have your workflow ready as shown below:

devneetmohanty07_4-1717431145043.png

 

Now, publish your action and then use all the actions of the same business object where you have done the changes in your process studio while interacting with the excel file in order to avoid any exceptions. I have a sample process studio workflow shown below:

 

devneetmohanty07_5-1717431260599.png

 

Here, I am creating an excel instance, then opening my excel file, then making it visible on the screen and then I use my new created action which has the below parameters:

devneetmohanty07_6-1717431315118.png

 

As you can see my image got inserted with dimensions 600X700 starting from cell A25.

 

---------------------------------------------------------------------------------------------------------------------------------------
Hope this helps you out and if so, please mark the current thread as the 'Answer', so others can refer to the same for reference in future.
Regards,
Devneet Mohanty,
SS&C Blueprism Community MVP 2024,
Automation Architect,
Wonderbotz India Pvt. Ltd.

Thanks devneetmohanty07 for the feedback.
Your solution is very informative and I think it will certainly work.

I applied another solution which is duplicating the "Paste" action and replacing the "pasteSpecial..." line by sheet.paste.