VBA: How to crop image in cells of column B and save it in a folder with names from column A cells.

icesanta

Board Regular
Joined
Dec 17, 2015
Messages
65
Hi,

I have Column A with image names and column B with images. How can crop images (Up=0.5 cm , down= 0.6 cm, left = 1 cm, Right 1.5 cm) and save the images in a folder with file names in respective rows. Some cells can be blank in between. I have 1.5 k rows.
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Can any body please help me to tune the code to put the cropped image from B to C column to their respective rows.
Then I have another VBA code to extract picture from cells with their names from respective rows.

Code:
Sub CropPicture()

    Dim shpCrop As Shape
    Dim sngMemoLeft As Single
    Dim sngMemoTop As Single

    Set shpCrop = ActiveSheet.Shapes(Selection.Name)

    With shpCrop
        sngMemoLeft = .Left
        sngMemoTop = .Top
        With .PictureFormat
            .CropLeft = 10
            .CropTop = 10
            .CropBottom = 10
            .CropRight = 10
        End With
        .Left = sngMemoLeft
        .Top = sngMemoTop
    End With

End Sub
 
Last edited:
Upvote 0
Code:
Sub CropPicture()
  Dim shpCrop As Shape, s As Shape
  Dim sngMemoLeft As Single
  Dim sngMemoTop As Single
  
  If ActiveSheet.Shapes.Count = 0 Then Exit Sub
  For Each shpCrop In ActiveSheet.Shapes
    With shpCrop
      If .Type <> 13 Then GoTo NextShpCrop  '13=Picture
      If .TopLeftCell.Column <> 2 Then GoTo NextShpCrop
      sngMemoLeft = .TopLeftCell.Offset(, 1).Left
      sngMemoTop = .TopLeftCell.Offset(, 1).Top
      With .PictureFormat
        .CropLeft = 10
        .CropTop = 10
        .CropBottom = 10
        .CropRight =10
      End With
      .Left = sngMemoLeft
      .Top = sngMemoTop
    End With
NextShpCrop:
  Next shpCrop
End Sub
 
Last edited:
Upvote 0
Thank you. But I have grouped two image in each cell and the code is working in only one image.
Can any code work in grouped images in cells.
 
Upvote 0
I didn't get that.

I guess you would just do the math and divide the cell width by two. The 2nd image's Left would be the cell's Left plus 1/2 the cell's width.

After the crop, I am not sure things would turn out. I guess the only way I would know for sure is if you shared a file with before and after simple examples. Sites like dropbox.com or such can be used for such.
 
Upvote 0

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