By default shapes have their aspect ratio (relation W/H) locked ... so in fact both your .Height
and .Width
settings will change both dimensions (unless they are square from start). If you want perfect squares no matter what is the original W/H ratio of your shapes, unlock the aspect ratio.
Suggestion:
Sub Test()
Dim OleObj As OLEObject
Set OleObj = ActiveSheet.OLEObjects(1) ' embedded PDF A4 ... not icon
OleObj.ShapeRange.LockAspectRatio = msoFalse
OleObj.Height = 30
OleObj.Width = 30
End Sub
Tested wit a PDF originally A4 size ... one doesn't have to like the final look ;-)
If you want to maintain the aspect ratio but still want to fit your OLEObject into a 30x30 grid, you need to apply one single setting to the larger dimension, e.g.
' ....
If OleObj.Width > OleObj.Height Then
OleObj.Width = 30
Else
OleObj.Height = 30
End If
' ....
Then - to horizontally center the object you'd add (30 - OLEObj.Width)/2
to oCell.Left
etc etc ...
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…