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!
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