|
- Sub 批量插入图片()
- Dim wj As String
- Dim rng As Range
- Dim x As String
- Sheets("Sheet1").Select '选中要插入图片的工作表
- x = 1000 '最后一行的行号
- For i = 1 To x
- na = Cells(i, 2) '从第二列(即B列)得到员工名字,并以此名查找图片
- wj = "C:\Users\Administrator\Desktop\图片" & "" & na & ".jpg" '图片文件存储的路径与格式(.jpg)
- If Dir(wj) <> "" Then
- With Cells(i, 6)
- PicL = .Left + .Width * 0.05
- PicT = .Top + .Height * 0.05
- PicW = .Width * 0.9
- PicH = .Height * 0.9
- End With
-
- With ActiveSheet.Shapes.AddPicture(wj, True, True, 0, 0, -1, -1)
- End With
-
- Set shp = ActiveSheet.Shapes(ActiveSheet.Shapes.Count)
- rh = PicH / shp.Height
- rw = PicW / shp.Width
- r = IIf(rw > rh, rh, rw)
- shp.Left = PicL
- shp.Top = PicT
- shp.ScaleWidth r, msoFalse, msoScaleFromTopLeft
-
- End If
- Next
- MsgBox "图片插入完毕"
- End Sub
复制代码
|
|