VBA Code to insert a picture into a cell

Malcolm torishi

Board Regular
Joined
Apr 26, 2013
Messages
219
Hi does any one know if you can insert a picture, file name say Tom, into a cell. So if I have the word Tom in a drop down box in cell A1. I would like the picture of Tom to appear in cell B1 and sized to fit in a cell say 100x 100. And if I change the name to say to Jack then Jacks photo will appear in cell B1. The photos are saved on my desktop. If anyone can help I would appreciate it
thank you
 
It means that you are going to make changes to the sheet "OUT" and the sheet "PhotoID 1" in the cell "B6" a new data will be reflected.
Then try the following:


Code:
Private Sub Worksheet_Calculate()
  Dim myPict As Picture, PictureLoc As String, sh As Worksheet
  Set sh = Sheets("[B][COLOR=#ff0000]PhotoID 1[/COLOR][/B]")
  On Error Resume Next
  [COLOR=#0000ff]sh.[/COLOR]DrawingObjects("img_tmp").Delete
  On Error GoTo 0
  
  PictureLoc = "C:\Users\proctm\Desktop\image\" & [COLOR=#0000ff]sh.[/COLOR]Range("B6").Value & ".jpeg"
  With [COLOR=#0000ff]sh.[/COLOR]Range("C4")
    Set myPict = sh.Pictures.Insert(PictureLoc)
    .RowHeight = 19.5
    myPict.Name = "img_tmp"
    myPict.Top = .Top
    myPict.Height = 375
    myPict.Width = 375
    myPict.Left = .Left
    myPict.Placement = xlMoveAndSize
  End With
End Sub
 
Upvote 0

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Dante
what can I say but Thank You ,it works brilliant. The photos insert into the correct place and change using the formula.
There is one other thing that’s cropped up from this thou, because I have the following Module that inserts a ticking clock on to a worksheet. The whole work book command buttons and the photos you helped me get to insert on a worksheet keeps flickering. The code for the clock is as below. Would you know how to stop this flickering please. Thank you if you can help. Have I tried to insert
Application.ScreenUpdating = False
Application.ScreenUpdating = True
at the beginning and end of your VBA Code to insert the photos. But it’s not helped

Dim SchedRecalc As Date
Sub Recalc()
With Sheet1.Range("Z4")
.Value = Format(Time, "hh:mm:ss AM/PM")
End With
Call Settime
End Sub


Sub Settime()
SchedRecalc = Now + TimeValue("00:00:01")
Application.OnTime SchedRecalc, "Recalc"
End Sub


Sub Disable()
On Error Resume Next
Application.OnTime EarliestTime:=SchedRecalc, Procedure:="Recalc", Schedule:=False
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,170
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