I’m using Excel 2007 and I’m trying to figure out if there is a way to insert a photo in a randomly selected cell and have both the photo and cell be re-sized the same using VBA
Example below
.Height = Application.InchesToPoints(1.5)
.Width = Application.InchesToPoints(1.75)
Currently I’m using code below to insert a photo into a pre sized cell, preselected cell.
Using my present method takes up to much space if photos are not used, so what I’m trying to do is save open space on a sheet if areas are not used for photos
Any possible suggestions
Dim sFile As Variant, r As Range Set r = Range("A1") sFile = Application.GetOpenFilename(FileFilter:="Pic Files (*.jpg;*.bmp), *.jpg;*.bmp", Title:="Browse to select a picture") If sFile = False Then Exit Sub ActiveSheet.Unprotect "" Dim i As Long For i = ActiveSheet.Pictures.Count To 1 Step -1 If ActiveSheet.Pictures(i).Top = r.Top And _ ActiveSheet.Pictures(i).Left = r.Left Then ActiveSheet.Pictures(i).Delete End If Next i With ActiveSheet.Pictures.Insert(sFile).ShapeRange .LockAspectRatio = True .Top = r.Top .Left = r.Left .Height = r.RowHeight * r.MergeArea.Rows.Count End With ActiveSheet.Protect ""