Sub 插入圖檔()
Dim uR As Range, uFile$, Row&, uShp As Shape
With ActiveSheet.Pictures
If .Count > 0 Then .Delete
End With
'↑刪除原有圖片
For Row = 2 To 999
Set uR = Range("C" & Row)
If uR = "" Or uR(1, 7) = "" Then GoTo 101
uFile = "D:\image\" & uR & "_W" & uR(1, 7) & ".JPG"
If Dir(uFile) = "" Then uFile = "D:\image\" & [A2] & ".jpg"
Set uR = uR(1, 9)
<插入圖檔.方法1>
With ActiveSheet.Pictures.Insert(uFile)
.Top = uR.Top
.Left = uR.Left
.Width = uR.Width
.Height = uR.Height
.Placement = xlMoveAndSize
.PrintObject = True
End With
<插入圖檔.方法2>取消以檔案連結方式插圖
Set uShp = ActiveSheet.Shapes.AddPicture(uFile, False, True, _
uR.Left, uR.Top, uR.Width, uR.Height)
With uShp
.Placement = xlMoveAndSize
.ControlFormat.PrintObject = True
End With
101: Next
End Sub
2016年3月23日 星期三
Excel VBA插入圖檔程式碼
■程式碼:
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言