I made asmall eror
from
If pict.Height > 100 Then
Crop = (CellWidth - pict.Width) / 2
to
If pict.Height > 100 Then
Crop = (CellHeight - pict.Height) / 2
- Show quoted text -
Hi,
Thanks, but it seems that I am doing something wrong. Below is the
Complete Macro that I have know can you look and see what I am doing
wrong.
Sub add_pictures()
Const PictureHeight = 120
DefaultPicture = "O:\MERCHGRP\AAB\pics\Mpics
\Picture_not_Available.jpg"
Application.ScreenUpdating = False
'delete pictures
For Each shp In ActiveSheet.Shapes
If shp.Type = msoPicture Then
shp.Delete
End If
Next shp
LastCol = Cells(4, Columns.Count).End(xlToLeft).Row
Rows(9).RowHeight = PictureHeight
For Each Cell In Range("B4:IV4")
If Cell <> "" Then
Cell.Offset(-3, 0).ClearContents
PictureFound = Dir(Cell.Value)
If PictureFound <> "" Then
Set pict = ActiveSheet.Pictures. _
Insert(Cell.Value)
pict.ShapeRange.LockAspectRatio = msoTrue
pict.ShapeRange.Height = PictureHeight
pictwidth = pict.Width
CellWidth = Cells(9, Cell.Column).Width
WidthBorder = CellWidth - pictwidth
pict.Left = Cells(9, Cell.Column).Left + (WidthBorder / 1.8)
PictHeight = pict.Height
CellHeight = Cells(9, Cell.Column).Height
HeightBorder = CellHeight - PictHeight
pict.Top = Cells(9, Cell.Column).Top + (HeightBorder / 1.8)
If pict.Width > pict.Height Then
Crop = (CellWidth - pict.Width) / 2
pict.PictureFormat.CropLeft = Crop
pict.PictureFormat.CropRight = Crop
End If
If pict.Height > pict.Width Then
Crop = (CellHeight - pict.Height) / 2
pict.PictureFormat.CropTop = Crop
pict.PictureFormat.CropBottom = Crop
End If
Else
Set pict = ActiveSheet.Pictures. _
Insert(DefaultPicture)
pict.ShapeRange.LockAspectRatio = msoTrue
pict.ShapeRange.Height = PictureHeight
pictwidth = pict.Width
CellWidth = Cells(9, Cell.Column).Width
WidthBorder = CellWidth - pictwidth
pict.Left = Cells(9, Cell.Column).Left + (WidthBorder / 1.8)
PictHeight = pict.Height
CellHeight = Cells(9, Cell.Column).Height
HeightBorder = CellHeight - PictHeight
pict.Top = Cells(9, Cell.Column).Top + (HeightBorder / 1.8)
End If
End If 'new line
Next Cell
Exit Sub 'new line
End Sub