×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Image in cell

Image in cell

Image in cell

(OP)
Hi,
Can we paste an image in a particular cell like text?

Thanks in advance.

Regards,
Ravi

RE: Image in cell

Hi,

Excel is an object based application. A object inherits some of it’s properties from the parent object.

For instance the Workbook Object inherits from the Excel Application. The Worksheet inherits properties from the Workbook. The cell Range inherits properties from the Worksheet.

An Image would inherit properties from the Worksheet, just as a Range does.

So an Image Object cannot be assciated with a specific Range (cell) directly, but only by way of that specific Range’s position properties (Top, Left, Height, Width)

CODE

With Img.ShapeRange
   .Top = YourCell.Top
   .Left = YourCell.Left
   .Height = YourCell.Height
   .Width = YourCell.Width
End With 
You may need to chsnge the LockAspectRatio property your image prior to positioning & sizing.

You might also check out FAQ707-4594: How to use the Watch Window as a Power Programming Tool

Skip,

glassesJust traded in my OLD subtlety...
for a NUance!tongue

RE: Image in cell

Yes, we can. Sort of. What you can do is anchor it to the cell that the image's top left corner is over

In code, that would simply be something like

CODE

    Range("E2").Select
    ActiveSheet.Pictures.Insert("<pathtomyimage>").Select
    Selection.Placement = xlMove 

but this doesn't prevent it accidentally being moved by sloppy mouse clicking ... (although that can be prevented by Protecting the spreadsheet as by default the anchor is locked)


RE: Image in cell

A different approach: add comment and fill its background with image. For hidden comments you will get hover effect - images will be visible when you move mouse over cell, the comment can be bigger than cell without limiting functionality.

CODE -->

Sub AddCommentWithImage()
With Range("A1").AddComment
    .Visible = False
    .Text Text:=""
    With .Shape
        .Fill.UserPicture "D:\x\test.jpg"
        .ScaleWidth 2.5, msoFalse
        .ScaleHeight 3.66, msoFalse
    End With
End With
End Sub 

combo

RE: Image in cell

(OP)
Hi all,
Thanks for the reply.
Our requirement is to insert image in a cell and should stick to that particular cell. Which seems to be not possible.

/ravi

RE: Image in cell

How about this?

CODE

'
    Dim oIMG As Object

    With ActiveSheet
        .Pictures.Insert("<pathtomyimage>").Select
        Set oIMG = .Shapes(.Shapes.Count)
        With .Cells(2, "E")      'your cell referenced here
            oIMG.Placement = xlMoveAndSize
            oIMG.LockAspectRatio = msoFalse
            oIMG.Height = .RowHeight
            oIMG.Width = .Width
            oIMG.Top = .Top
            oIMG.Left = .Left
        End With
    End With 

Skip,

glassesJust traded in my OLD subtlety...
for a NUance!tongue

RE: Image in cell

(OP)
Hi @SkipVought,
it's not working. invalid outside procedure error.


/ravi

RE: Image in cell

On what statement?

And please post your entire code, as I gave you merely a code snippet.

Skip,

glassesJust traded in my OLD subtlety...
for a NUance!tongue

RE: Image in cell

You need to put Skip's code in a sub or function … however, it won't meet your "insert image in a cell and should stick to that particular cell" requirement, as Excel doesn't actually have the capability to put an image in a cell. It can put it over the cell, and anchor it to that cell, as previously advised (and Skip's code heightens the illusion by scaling the image to the size of the cell it is over)

RE: Image in cell

Actually, the image/picture can initially be anywhere on the sheet. The position and size at the instant of creation is irrelevant.

It is sized to fit and positioned to fit virtually immediately. And the image’s Placement property is assigned to allow it to both move and size as the cell may move or change size.

Skip,

glassesJust traded in my OLD subtlety...
for a NUance!tongue

RE: Image in cell

Is that aimed at me or the OP?

If it is me, then not quite sure what point you are making. The only real initial difference between your example and mine is how we ensure the top left corner of the picture is over the cell we want it to anchor to - in my simple example this is the currently selected cell, in your case to a cell you nominate via code. In neither your code nor my code can we make the image actually stick with the cell, we can only give a pseedo-appearance of that - but it is quite easy to accidentally knock the image to a different cell (to which it will then appear to be anchored instead). We can get closer to the OPs requirements if we lock the image and then Protect the spreadsheet, but that causes some problems of its own.

RE: Image in cell

(OP)
Hi,
Thank you all for your replies.
We are trying to do something with OCR for text conversion from image.

/Ravi

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close