VBA Inserting photos based on cell values

Kakapo

New Member
Joined
Nov 1, 2018
Messages
1
Hi lovely Mr Excel people,

It's been a while since I've hung out here...

I'm trying to replace a list of photo file numbers in a worksheet with the actual photos, which are always saved in a set location (actually they aren't but I'll sort that later)

Photos should resize to match the width of column they are pasted into but retain aspect ratio.

The row should be resized to fit the photo (but that's another step for later, haven't coded this yet)

I haven't written any VBA for ages so my syntax sucks, hence this code which I've adapted from a classic post won't run any more. Any help greatly appreciated!

Code:
Sub InsertPhotoFromFile()
'
' Inserts Photos from File based on values in cells
'
'
Dim cCell As Range


'Find the range of cells where photos to be inserted
   Range("b3").Select
   Range(Selection, Selection.End(xlDown)).Select
   
For Each cCell In Selection
If cCell.Value <> "" Then
On Error Resume Next


With ActiveSheet.Shapes.AddPicture
            .Filename ("FILEPATH\" & cCell.Value & ".jpg")
            .LinkToFile = False
            .SaveWithDocument = True
            .ShapeRange.LockAspectRatio = True
            .Top = cCell.Top
            .Left = cCell.Left
            .Width = cCell.Width
End With


End If


Next cCell


End Sub
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.

Forum statistics

Threads
1,223,896
Messages
6,175,265
Members
452,627
Latest member
KitkatToby

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