Fit Image Inside A Shape In Excel

In this post we will see how to fill a shape with image in excel.

I am going to explain how we could automatically fit an image inside a shape in excel, we could insert an image inside a shape manually also but here in this post we will how we can do that with the help of excel macro.

If you have tried to fill an image inside shape then you would know how annoying this task is as the image needs to be adjusted so carefully within the shape and sometimes the result is a distorted image somehow fit inside the shape.

With the help of vba we could get rid of adjusting the image manually inside a shape.





Below is an example in which we can see we have a rectangular shape in excel sheet and we want to fit an image in it.

shape in which we want to fit image

The name of the rectangle is “”Rectangle 1”.

Step 1

We will create a macro in excel to auto insert an image inside a shape.

Open VB editor from Developer tab in excel as shown in the figure.

open vba editor to write vba to fit image inside a shape

Step 2

Insert a module in which we will write a small macro to fit an image inside a shape.

insert a modult to write macro to fit an image inside a shape




Step 3

Now double click the newly created module to open that and paste the below code in the module.

Option Explicit

Public Sub AddPicAndAdjust()

    Dim shp As ShapeRange

    Set shp = ActiveSheet.Shapes.Range(Array(“Rectangle 1”))

    With shp.Fill

        .Visible = msoTrue

        .UserPicture “C:\Users\rvdsr\Desktop\Flower.png” ‘<== Add pic location

        .TextureTile = msoFalse

        .RotateWithObject = msoTrue

    End With

    With shp

        .LockAspectRatio = msoFalse

        .IncrementLeft 2

    End With

End Sub

This program defines an object for shape and assigns the picture given in the location to this object.

we have pasted the program in vb editor to fit an image inside a shape

Step  4

Run the program by pressing F5 or by play button.

You can see that after the program is run, we have the image inserted within the shape.

image is fit inside a shape in excel




I had a flower picture in my desktop which I was able to fit in the given shape.

Edit the location to specify the path for your image.

Hope this helped.

Share The Knowledge

Random Posts

Leave a Reply