|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
写个宏解决——
- Option Explicit
- Sub InsertPhoto()
- On Error Resume Next
- Application.ScreenUpdating = False
- Dim shp As Shape, rng As Range, adr As String, l As Single, t As Single, h As Single, w As Single
- With Sheet1
- For Each shp In .Shapes '先清除表中已有照片
- If shp.Type = msoPicture Then shp.Delete
- Next
- Set rng = .Cells.Find("准考证号码", LookIn:=xlValues)
- If Not rng Is Nothing Then
- adr = rng.Address
- Do
- l = rng.Offset(0, 3).Left '插入照片的位置-左
- t = rng.Offset(0, 3).Top '插入照片的位置-上
- h = rng.Offset(0, 3).Height * 2.18 '照片的高度
- w = rng.Offset(0, 3).Width '照片的宽度
- .Shapes.AddPicture ThisWorkbook.Path & "/照片/" & rng.Offset(0, 1).Value & ".jpg", False, True, l, t, w, h
- Set rng = .Cells.FindNext(rng)
- Loop While Not rng Is Nothing And rng.Address <> adr
- End If
- End With
- Application.ScreenUpdating = True
- End Sub
复制代码
|
|