Hello - I had an older version of excel, then I upgraded to excel 2013. The macro I had isn't working anymore on the newer version of excel.
Description:
In column A i have image file names and I use the macro below to insert the photos that correspond with those photos. The photos are in a folder on my desktop.
I'm also having issues inserting the photos if the photo's exceed a certain size (length x width). Is there a way to adjust this macro so the images can still be inserted irregardless of their size limitations in excel?
Img Name
c-101.jpg
c-101e-6.jpg
c-131-1.jpg
c-132-1.jpg
Macro:
Public Sub Test()
Dim sPath As String
Dim oCell As Range
Dim oRange As Range
Dim oPicture As Shape
Dim oSheet As Worksheet
sPath = "C:\Documents and Settings\gtsuyuki\Desktop\New Folder\" 'Change to suit
Set oSheet = ActiveSheet
Set oRange = oSheet.Range("A2:A5")
For Each oCell In oRange
If Dir(sPath & oCell.Text) <> "" And oCell.Value <> "" Then
Set oPicture = oSheet.Shapes.AddPicture(Filename:=sPath & oCell, LinktoFile:=msoFalse, savewithdocument:=msoTrue, Left:=oCell.Left, Top:=oCell.Top, Width:=1, Height:=1)
oPicture.ScaleHeight 1, True
oPicture.ScaleWidth 1, True
If oPicture.Height > 409 Then oPicture.Height = 409
oCell.RowHeight = oPicture.Height
oCell.ColumnWidth = oPicture.Width / 4
Else
oCell.Offset(0, 1).Value = "Image file not found"
End If
Next oCell
End Sub
Bookmarks