Import, crop, rotate, delete, position the image in VBA Excel

Import delete rotate crop image in excel using vba

Objective

To import, crop, rotate, delete, position the image in VBA Excel.

Approach

Here we have imported an image in the excel sheet then imported,cropped , rotated ,position it.We can also delete the image, if required.

What this code does

  1. Import a jpeg file in the excel file
  2. Crop, rotate , delete the file
  3. Change the position of the file

Steps

We have taken the below shown steps in the code-

  1. Import the image from local drive path to excel sheet
  2. Crop the image from left,right,top,bottom
  3. Rotate the image to 10 degree
  4. Position the image from left and top
  5. Delete part is commented in code

Image shown just below is the original image on a excel worksheet.

 

Import delete rotate crop image in excel using vba

 

Now in this second image shown below, you can see that black colour borders have been cropped and image is rotated to right.

 

Import delete rotate crop image in excel using vba

 

Code 

Sub InsertPicture()
Dim MyPicture As Shape
'Add a image in the sheet1
Set MyPicture = Sheets("sheet1").Shapes.AddPicture("C:\Users\yourusername\Desktop\test1\Crop_Image\sampleimage.jpg", True, True, 100, 100, 500, 500)
'Crop the imported image
With MyPicture.PictureFormat
    .CropLeft = 40
    .CropRight = 60
    .CropTop = 40
    .CropBottom = 40
End With

'Rotate and change the position of image
With MyPicture
     .IncrementRotation 10
     .Left = 200
     .Top = 200
End With

'Delete the impage,if needed
'MyPicture.Delete
End Sub

 

Note

  1. You can use this approach when you want to import an image or crop a logo.
  2. There are other methods which you can use to flip, count etc.

Post you may like

Send mail with attachment to multiple recipients in outlook using VBA Excel

1 comment on “Import, crop, rotate, delete, position the image in VBA Excel

Comments are closed.