none
How to insert image to within a cell?

    Question

  • Hi,

     

    I would like to ask a question on inserting images into an Excel 2010 worksheet.

     

    Using the ordinary operation “Insert TabPicture”, the result is like an image floating in the worksheet which doesn’t belong to any particular cell.

     

    Is there a way to fix the inserted picture within a particular cell so that the border of picture is aligned with cell border and the image is resized according to the cell dimension, or alternative, can be configured to maintain its original aspect ratio so that only vertical or horizontal borders are aligned?

     

    Or, rather than hoping to insert image within a cell, is it possible to assign an image as the background as a cell? I tried “Format cellsFill” but found no such option.

     

     

     

    Bob

    Monday, September 12, 2011 6:30 AM

Answers

  • Bob, No you cannot "Insert" an image "inside" a cell but yes, you can arrange it in such a way that it "appears" that it is inside a particular cell by handling then image .Top, .Width, .Height and .Left property and making it the same as the cells .Top, .Width, .Height and .Left

    For example

    Sub Sample()
        '~~> Replace "Picture 1" with the relevant image name
        '~~> Replace "Sheet1" with the relevant Sheet name
        With Sheets("Sheet1").Shapes("Picture 1")
            .LockAspectRatio = msoFalse
            .Top = Range("A200").Top
            .Left = Range("A200").Left
            .Width = Range("A200").Width
            .Height = Range("A200").Height
        End With
    End Sub
    



    Sid (A good exercise for the Heart is to bend down and help another up) Please do not email me your questions. I do not answer questions by email unless I get paid for it :) If you want, create a thread in Excel forum and email me the link and I will help you if I can.
    • Marked as answer by Bob Sun Monday, September 12, 2011 9:08 AM
    Monday, September 12, 2011 7:55 AM
    Moderator

All replies

  • Bob, No you cannot "Insert" an image "inside" a cell but yes, you can arrange it in such a way that it "appears" that it is inside a particular cell by handling then image .Top, .Width, .Height and .Left property and making it the same as the cells .Top, .Width, .Height and .Left

    For example

    Sub Sample()
        '~~> Replace "Picture 1" with the relevant image name
        '~~> Replace "Sheet1" with the relevant Sheet name
        With Sheets("Sheet1").Shapes("Picture 1")
            .LockAspectRatio = msoFalse
            .Top = Range("A200").Top
            .Left = Range("A200").Left
            .Width = Range("A200").Width
            .Height = Range("A200").Height
        End With
    End Sub
    



    Sid (A good exercise for the Heart is to bend down and help another up) Please do not email me your questions. I do not answer questions by email unless I get paid for it :) If you want, create a thread in Excel forum and email me the link and I will help you if I can.
    • Marked as answer by Bob Sun Monday, September 12, 2011 9:08 AM
    Monday, September 12, 2011 7:55 AM
    Moderator
  • Sid,

     

    This worked, thanks very much.

     

     

    Bob

    Monday, September 12, 2011 9:08 AM