2016-08-03 110 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你好,請標記爲答案 –