我有這段代碼可以將 B 列中的一組 URL 轉換為 C 列中的影像,但出現錯誤:
無法獲取圖片類的插入屬性。我的代碼:
Private Sub Insert_Pic()
Dim pic As String
Dim myPicture As Picture
Dim rng As Range
Dim item As Range
lRow = ActiveSheet.Cells(Rows.Count, 3).End(xlUp).Row
Set rng = Range("B3:B" & lRow)
For Each item In rng
pic = item.Offset(0, -1)
If pic = "" Then Exit Sub
Set myPicture = ActiveSheet.Pictures.Insert(pic)
With myPicture
.ShapeRange.LockAspectRatio = msoFalse
.Width = item.Width
.Height = item.Height
.Top = Rows(item.Row).Top
.Left = Columns(item.Column).Left
.Placement = xlMoveAndSize
End With
Next
End Sub
謝謝你的幫助
uj5u.com熱心網友回復:
除錯中的演算法是從一些微小的東西開始,它可以作業,然后繼續。
作為開始 - 僅使用這 4 行并運行它們:
Sub TestMe()
Dim myPicAddress As String
myPicAddress = "https://www.vitoshacademy.com/wp-content/uploads/2016/02/va2.png"
Dim myPic As Picture
Set myPic = ActiveSheet.Pictures.Insert(myPicAddress)
End Sub
然后,開始處理您的代碼,將With-End With部分放入已經有效的代碼中:
Sub TestMe2()
Dim myPicAddress As String
myPicAddress = "https://www.vitoshacademy.com/wp-content/uploads/2016/02/va2.png"
Dim myPicture As Picture
Set myPicture = ActiveSheet.Pictures.Insert(myPicAddress)
Dim item As Range
Set item = ActiveSheet.Cells(5, 5)
With myPicture
.ShapeRange.LockAspectRatio = msoFalse
.Width = item.Width
.Height = item.Height
.Top = Rows(item.Row).Top
.Left = Columns(item.Column).Left
.Placement = xlMoveAndSize
End With
End Sub
最后,看一下回圈以及作為圖片字串傳遞的內容。錯誤可能隱藏在那里的某個地方。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/425908.html
