Photo alignment within a cell

ABabeNChrist
SilverLounger
Posts: 1868
Joined: 25 Jan 2010, 14:00
Location: Conroe, Texas

Photo alignment within a cell

Post by ABabeNChrist »

Is it possible when inserting a photo with the use of code to have photo align bottom center of cell.

Rick Rothstein
Microsoft MVP
Posts: 87
Joined: 10 Mar 2011, 05:38
Status: Microsoft MVP
Location: New Jersey in the US

Re: Photo alignment within a cell

Post by Rick Rothstein »

Try this sub (read the comments)...

Code: Select all

Sub AddPictureCenterBottomActiveCell()
  '  If you already have the picture on the worksheet, then add code to select
  '  it here in place of this next line of code (which inserts a new picture).
  ActiveSheet.Pictures.Insert("C:\Temp\SomePictureName.bmp").Select
  '  Move the selected picture into place with respect to the active cell
  Selection.Top = ActiveCell.Top + ActiveCell.Height - Selection.Height
  Selection.Left = ActiveCell.Left - (Selection.Width - ActiveCell.Width) / 2
End Sub
Note that if you already have the picture on the worksheet and are only going to move it, you will need to put in some error-trapping code to protect against the picture not being able to fit in the desired location. If, on the other hand, you use the code above, the picture will be placed as close to the desired location as possible without raising any error.
 

ABabeNChrist
SilverLounger
Posts: 1868
Joined: 25 Jan 2010, 14:00
Location: Conroe, Texas

Re: Photo alignment within a cell

Post by ABabeNChrist »

Thank You