2016-08-03 105 views
0

我已经阅读了几个论坛,但他们都没有为我工作。禁用锁定长宽比VBA - Excel

我从网上拉图片,并将它们插入我的电子表格。我希望所有这些图片具有相同的尺寸。

我的代码如下:

Dim img_url as string, picture as object 
img_url = Range("A1") 'Some url with an img 

With ActiveSheet.Pictures 
    Set Picture = ActiveSheet.Pictures.Insert(img_url) 
    Picture.LockAspectRatio = msoFalse 
    Picture.Width = 25 
    PictureHeight = 25 
End With 

我每次运行它,锁定纵横比的设定仍然选中,并且图像不是我要找的方格式。

任何意见将不胜感激。

由于

+0

'PictureHeight'应该是'Picture.Height'吗?另外,With'块似乎是多余的。 – jsheeran

+0

'LockAspectRatio = msoFalse'是'Shape'对象库的成员 –

+0

@marldog在 –

回答

1

使用下面的代码,所述LockAspectRatio属性是Picture.ShapeRange对象的属性,而不是Picture

Option Explicit 

Sub ImageAttributes() 

Dim img_url As String 
Dim picture As Object 

img_url = Range("A1") 'Some url with an img 

With ActiveSheet 
    Set picture = .Pictures.Insert(img_url) 
    With picture 
     With .ShapeRange 
      .LockAspectRatio = msoFalse 
      .Width = 25 
      .Height = 25 
     End With 
    End With 
End With 


End Sub 
+0

以下看到我的回答非常感谢。完美工作。 – marldog

+0

@marldog你好,请标记为答案 –