3 回答

TA貢獻1798條經驗 獲得超3個贊
嘗試這個:
With xlApp.ActiveSheet.Pictures.Insert(PicPath)
With .ShapeRange
.LockAspectRatio = msoTrue
.Width = 75
.Height = 100
End With
.Left = xlApp.ActiveSheet.Cells(i, 20).Left
.Top = xlApp.ActiveSheet.Cells(i, 20).Top
.Placement = 1
.PrintObject = True
End With
最好不要在Excel中選擇任何內容,通常這從來沒有必要,這會使代碼變慢。

TA貢獻1725條經驗 獲得超8個贊
查看發布的答案,我認為這段代碼對于某人來說也是一種選擇。上面沒有人.Shapes.AddPicture在他們的代碼中使用過.Pictures.Insert()
Dim myPic As Object
Dim picpath As String
picpath = "C:\Users\photo.jpg" 'example photo path
Set myPic = ws.Shapes.AddPicture(picpath, False, True, 20, 20, -1, -1)
With myPic
.Width = 25
.Height = 25
.Top = xlApp.Cells(i, 20).Top 'according to variables from correct answer
.Left = xlApp.Cells(i, 20).Left
.LockAspectRatio = msoFalse
End With
我正在使用Excel2013。還意識到您需要填寫中的所有參數.AddPicture,因為錯誤“參數不是可選的”??粗@個,您可能會問為什么我將Height和設置Width為-1,但這沒關系,因為這些參數設置在With方括號之間。
希望它對某人也可能有用:)
添加回答
舉報