cancel
Showing results for 
Search instead for 
Did you mean: 

How to delete picture in EXCEL workbook?

HWXie
Level 3
There are 2 pictures in my workbook and I want to delete 1 of them.
How can I use BluePrism to select the picture and delete it?

regards!
1 REPLY 1

Hi 

In there isnt any functionality within blue prism that will do that for you currently so you would need to create new actions for this. If you know the name of the image you want to delete then you just need to add one action and create a code stage within it to delete the named image. If you dont know the name of the image then you might neeed to get a list of the image names and then loop these to delete the one you want to delete. I've provided code for the first action Delete image and the second code List images below. Hope this helps 🙂

Delete Image - Inputs are Handle, Source_Workbook, Source_Worksheet and Image_Name. The outputs are Success and Message

Dim wb, ws As Object
Dim excel, sheet, image As Object

Try

wb = GetWorkbook(Handle, Source_Workbook)
ws = GetWorksheet(Handle, Source_Workbook, Source_Worksheet)

wb.Activate()
ws.Activate()
excel = ws.Application
sheet = excel.ActiveSheet
image = sheet.Shapes(Image_Name)
image.Select()

image.Delete

Success = True

Catch e As Exception
Success = False
Message = e.Message
Finally
wb = Nothing
ws = Nothing
excel = Nothing
sheet = Nothing
image = Nothing
End Try
---------------------------------

List images - Inputs are Handle, Workbook and Worksheet. Outputs are as a collection called Images
---------------------------------------------------------
Dim wb, ws, excel, sheet As Object

wb = GetWorkbook(Handle, Workbook)
ws = GetWorksheet(Handle, Workbook, Worksheet)

wb.Activate()
ws.Activate()

excel = ws.Application
sheet = excel.ActiveSheet

Dim Table As New DataTable
Table.Columns.Add("Name", GetType(String))

Dim image as Object

For Each image In wb.Worksheets(Worksheet).Shapes
Table.Rows.Add(image.Name)
Next

Images = Table