3 回答

TA貢獻(xiàn)1798條經(jīng)驗(yàn) 獲得超3個(gè)贊
嘗試這個(gè):
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中選擇任何內(nèi)容,通常這從來沒有必要,這會(huì)使代碼變慢。

TA貢獻(xiàn)1725條經(jīng)驗(yàn) 獲得超8個(gè)贊
查看發(fā)布的答案,我認(rèn)為這段代碼對(duì)于某人來說也是一種選擇。上面沒有人.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。還意識(shí)到您需要填寫中的所有參數(shù).AddPicture,因?yàn)殄e(cuò)誤“參數(shù)不是可選的”。看著這個(gè),您可能會(huì)問為什么我將Height和設(shè)置Width為-1,但這沒關(guān)系,因?yàn)檫@些參數(shù)設(shè)置在With方括號(hào)之間。
希望它對(duì)某人也可能有用:)
添加回答
舉報(bào)