cancel
Showing results for 
Search instead for 
Did you mean: 

How to identify an image is present in the word document?

HarishM2
Level 6
Hi,

How to  verify whether any image present in the word document or not?

I tried Select All> Copy to clipboard >Get Clipboard but as a result I'm getting only text in the body.



Thanks,
Harish

------------------------------
Harish
RPA Developer
------------------------------
1 BEST ANSWER

Helpful Answers

Hi Harish

I had a quick test of it and looks like just needed a small tweak to make it work. The updated code is below, I have added in some additional code which is commented (highlighted in green) out as im not sure you will need it but there may be inline images need to be converted on you doc before they can be identified so just remove the comments if you need to use it but if not just leave the comment so the code is ignored. Remember to add in the parameters for the code stage with Handle, documentname as inputs and Images as the output collection. Good luck 🙂

Dim d As Object = GetDocument(handle,documentname)
Dim w As Object = d.Application
'Dim iShape As object

w.Activate()

'For Each iShape In w.ActiveDocument.InLineShapes
'iShape.ConvertToShape
'Next iShape

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

Dim image as Object

For Each image In w.ActiveDocument.Shapes
dataTable.Rows.Add(image.Name)
Next

Images = dataTable

------------------------------
Michael ONeil
Technical Lead developer
Everis Consultancy
Europe/London
------------------------------

View answer in original post

6 REPLIES 6

Ben.Lyons1
Staff
Staff
Hi Harish,

That's an interesting challenge to have.

I can't think of a simple way to do this, though it's likely possible if you or someone you know has a good understanding of VBA.

In the event you don't it would be possible to use the Word VBO to save it as a PDF and then use the DX Asset from Boost Robotics (https://digitalexchange.blueprism.com/dx/entry/58413/solution/utility---pdf) to get images. This asset can be downloaded from the previous link, but comes with an annual license cost of 249 euros.

I'll keep thinking on it, but that's all that's coming to mind at the moment.

------------------------------
Ben Lyons
------------------------------
Ben Lyons
Principal Product Specialist - Decipher
SS&C Blue Prism
UK based

Hi Harish,

I previously created something to convert a pdf to excel and afterwards list the images in the excel file in order to delete them. I have provided the code below that lists the image names in a table this would obviously need to be modified for use in word but should provide you a starting point. Ive included an example of how the code might look if used for word but this is untested so you might need to finish the development on it. Hope this helps 🙂

excel code:
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

Possible word code (untested):
Dim d As Object = GetDocument(handle,documentname)
Dim w As Object = d.Application

w.Activate()

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

Dim image as Object

For Each image In w.ActiveDocument.Shapes
Table.Rows.Add(image.Name)
Next

Images = Table




------------------------------
Michael ONeil
Technical Lead developer
Everis Consultancy
Europe/London
------------------------------

Thanks for Responding. I will check  that asset in DX.

------------------------------
Harish
RPA Developer
------------------------------

Thanks for responding Michael. I tried the code but it is returning empty table.

------------------------------
Harish
RPA Developer
------------------------------

Hi Harish

I had a quick test of it and looks like just needed a small tweak to make it work. The updated code is below, I have added in some additional code which is commented (highlighted in green) out as im not sure you will need it but there may be inline images need to be converted on you doc before they can be identified so just remove the comments if you need to use it but if not just leave the comment so the code is ignored. Remember to add in the parameters for the code stage with Handle, documentname as inputs and Images as the output collection. Good luck 🙂

Dim d As Object = GetDocument(handle,documentname)
Dim w As Object = d.Application
'Dim iShape As object

w.Activate()

'For Each iShape In w.ActiveDocument.InLineShapes
'iShape.ConvertToShape
'Next iShape

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

Dim image as Object

For Each image In w.ActiveDocument.Shapes
dataTable.Rows.Add(image.Name)
Next

Images = dataTable

------------------------------
Michael ONeil
Technical Lead developer
Everis Consultancy
Europe/London
------------------------------

I uncommented the lines you mentioned above. Now it is able to identify the image. 


Thanks Michael

------------------------------
Harish
RPA Developer
------------------------------