步骤1)打开Excel,将“堆栈溢出的徽标复制到工作表:https://blog.stackoverflow.com/wp-content/uploads/stackoverflow-logo-300.png”
步骤2)复制并粘贴该徽标两次
步骤3)手动调整一个徽标到一些可笑的大小:http://i.imgur.com/87lIB8o.png
现在,如何通过vba将该讨厌的徽标调整到与原始徽标相同的大小?
我尝试了以下宏(是的,我尝试使用With / End With):
Sub sds()
ActiveSheet.Shapes.Range(Array("Picture 2")).Width = ActiveSheet.Shapes.Range(Array("Picture 1")).Width
ActiveSheet.Shapes.Range(Array("Picture 2")).Height = ActiveSheet.Shapes.Range(Array("Picture 1")).Height
End Sub它扭曲了它,最后它看起来像:http://i.imgur.com/e7BKq9y.png
发布于 2015-01-28 07:11:02
对于包含图像的形状,每个默认设置一个属性.LockAspectRatio = msoTrue。这将导致所描述的行为。
为了避免这种情况,您可以将其切换到msoFalse,然后更改.Height和.Width,然后再将其切换到msoTrue:
Sub picture_size()
ActiveSheet.Shapes.Range(Array("Picture 2")).LockAspectRatio = msoFalse
ActiveSheet.Shapes.Range(Array("Picture 2")).Width = ActiveSheet.Shapes.Range(Array("Picture 1")).Width
ActiveSheet.Shapes.Range(Array("Picture 2")).Height = ActiveSheet.Shapes.Range(Array("Picture 1")).Height
ActiveSheet.Shapes.Range(Array("Picture 2")).LockAspectRatio = msoTrue
End Sub但是,如果目标只是恢复原来的大小,那么:
Sub picture_100Percent()
ActiveSheet.Shapes.Range(Array("Picture 2")).ScaleHeight 1, msoTrue
End Subhttps://stackoverflow.com/questions/28186215
复制相似问题