This seems challenging. I'm looking for a macro to run that will:
With the code I've tried (below), the struggles I've had are:
- Insert a picture (would bring the user to the screen where they search for their picture)
- Place the picture in the cell they already had selected (e.g. B2 below)
- Size/scale the picture automatically to fully fit within the cell
- Preferred to leave gaps around all 4 edges of the picture to the cells but not a show stopper (see below)...centered?
- Picture must 'move and size with cells'
With the code I've tried (below), the struggles I've had are:
- Pictures (in horizontal orientation (e.g. B2)) are filling the height of the cell (they go beyond the width)
- Pictures (in the vertical orientation (e.g. B4)) are sizing the top edge as the height of the cell and placing the picture somewhere else in the worksheet
- NOTE: If I insert a vertical picture using the conventional methods, it goes in the selected cell.
VBA Code:
Sub InsertPic()
Dim fNameAndPath As Variant
Dim img As Picture
fNameAndPath = Application.GetOpenFilename
Set img = ActiveSheet.Pictures.Insert(fNameAndPath)
With img
.Left = ActiveCell.Left
.Top = ActiveCell.Top
.Width = ActiveCell.Width
.Height = ActiveCell.Height
.Placement = 1
.PrintObject = True
End With
End Sub