View Single Post
  #7   Report Post  
Posted to microsoft.public.excel.programming
joel joel is offline
external usenet poster
 
Posts: 9,101
Default Insert picture using Macro..

CellHeight = Range("A1").Height
CellWidth = Range("A1").Width

pict.LockAspectRatio = msoTrue
If pict.Width pict.Height Then
If pict.Width 100 Then
Crop = (CellWidth - pict.Width) / 2
pict.PictureFormat.CropLeft = Crop
pict.PictureFormat.CropRight = Crop
End If
Else
If pict.Height 100 Then
Crop = (CellWidth - pict.Width) / 2
pict.PictureFormat.CropTop = Crop
pict.PictureFormat.CropBottom = Crop
End If
End If
WidthBorder = CellWidth - pict.Width
pict.Left = Range("A1").Left + WidthBorder / 2

HeightBorder = CellHeight - pict.Height
pict.Top = Range("A1").Top + HeightBorder / 2


" wrote:

On Jun 19, 3:23 am, Joel wrote:
You need to get the height and width of the cell is is going into to center
the cell

CellHeight = range("A1").Height
CellWidth = range("A1").Width

pict.LockAspectRatio = msoTrue
if pict.width pict.height then
pict.width = 100
else
pict.height = 100
end if
WidthBorder = CellWidth - pict.width
pict.left = Range("A1").left + WidthBorder/2

HeightBorder = CellHeight - pict.height
pict.top = Range("A1").Top + HeightBorder/2



" wrote:
On Jun 18, 2:07 pm, wrote:
On Jun 18, 11:20 am, Joel wrote:


You need to get the larger of the width or height variable and adjust it to 100


pict.LockAspectRatio = msoTrue
if pict.width pict.height then

else
pict.height = 100
end if


" wrote:
I have amacrothat I use toinsertpictures in excel but I am having
difficulty with thepicturesize, I would like thepictureto keep the
Aspect Ratio but to have a maximum of 100 height and a maximum 100
width is this possible, any help is appreciated.
Thanks.- Hide quoted text -


- Show quoted text -


Thanks, you are great!.
Is there any way that I can center the pictures in the cell, because
when the width is than the height it ia scaling it to 100 but then
it is being placed slightly on the cell in to the left.
thanks- Hide quoted text -


- Show quoted text -


Hi,
I am wondering if this will work! I tried but it seems that I am doing
something wrong can you help please.


pict.LockAspectRatio = msoTrue
if pict.width pict.height then
pict.cropleft = 50
pict.cropright = 50
else
pict.height = 100
end if- Hide quoted text -


- Show quoted text -


Hi,
Is it possible to Crop the picture from left and right instead of
sizing it "pict.width = 100"
thanks.