Get the color of small images

haseft

Active Member
Joined
Jun 10, 2014
Messages
321
Hi!

I import some data from Word document and paste it into a worksheet.
The word document contain both text and many small images. The images are only with 4 colors, but many of them.
I want to get the color of images.

I get the RGB color number, but they all have the same number. It should be 4 different color number.
I wonder how I can dethatch a small Excel Worksheet in this Forum, so you can se the images.

HTML:
Function ShapeAtActiveCell() As String
'
  Dim Sh As Shape
  For Each Sh In ActiveSheet.Shapes
    If Sh.TopLeftCell.Address = ActiveCell.Address Then
      ShapeAtActiveCell = Sh.Name
      ActiveSheet.Shapes(ShapeAtActiveCell).Select
      Exit Function
    End If
  Next
End Function

'-------------------------------------

Sub GetColor()
  Dim shp As Shape
  Dim R As Integer, G As Integer, B As Integer
  Dim colr As Double
  Dim j As Long
  j = 2
  
Worksheets("Sheet1").Activate
Range("B2").Select
For i = 1 To 4
   ActiveSheet.Shapes(ShapeAtActiveCell).Select
   Set shp = ActiveSheet.Shapes(Selection.Name)
   colr = shp.Fill.BackColor.RGB
   R = colr Mod 256
   G = (colr \ 256) Mod 256
   B = (colr \ 256 \ 256) Mod 256
   
   Cells(j, "C").Value = colr
   Cells(j, "D").Value = R
   Cells(j, "E").Value = G
   Cells(j, "F").Value = B
   
  ActiveCell.Offset(1, 0).Select
  j = j + 1
Next i
  
End Sub
https://1drv.ms/f/s!AuZtyv5z6GO9aA-J72juKjF4MBg
 
Last edited by a moderator:

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.

Forum statistics

Threads
1,224,823
Messages
6,181,177
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top