Hi, I am using the below code to check for existing image (and delete if it exists), and then add an image into a cell range - centred and fit to size (/1.05). This works fine in Excel 2007, but in Excel 2010, the image is being squashed horizontally > < ... any ideas why?
Thanks,
Matt
Code:
Sub InsertPicture()
Dim sPicture As String, pic As Picture
On Error GoTo Noimage
ActiveSheet.Shapes("ProductImage").Select
If MsgBox("This will replace the existing image.", vbOKCancel + vbExclamation, "Are you sure?") = vbCancel Then Exit Sub
Selection.Delete
Noimage:
cell = Range("Image").Select
MyRange = Selection.Address
sPicture = Application.GetOpenFilename _
("Pictures (*.gif; *.jpg; *.bmp; *.tif), *.gif; *.jpg; *.bmp; *.tif", _
, "Select Picture to Import")
If sPicture = "False" Then Exit Sub
Set pic = ActiveSheet.Pictures.Insert(sPicture)
pic.Select
Selection.Name = "ProductImage"
With pic
.ShapeRange.LockAspectRatio = msoTrue
If .Width > .Height Then
.Width = Range(MyRange).Width / 1.05
If .Height > Range(MyRange).Height Then .Height = Range(MyRange).Height / 1.05
Else
.Height = Range(MyRange).Height / 1.05
If .Width > Range(MyRange).Width Then .Width = Range(MyRange).Width / 1.05
End If
.Top = ActiveCell.Top + ((Range(MyRange).Height - .Height) / 2)
.Left = ActiveCell.Left + ((Range(MyRange).Width - .Width) / 2)
.Placement = xlMoveAndSize
End With
Range("B27").Select
Range("B27").Value = 0
Range("D26").Select
Set pic = Nothing
End Sub
Thanks,
Matt