|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
之前不是有老师解答了吗,无需重复发贴
试试:
- Sub Fr_Pic()
- Dim fr, myPath$, rng As Range
- Dim i&, j&, k&, n&, r&
- 'On Error Resume Next
- Call Delshp
- myPath = ThisWorkbook.Path & ""
- With CreateObject("Wscript.Shell") 'VBA调用Dos命令
- fr = Split(.exec("cmd /c dir /a-d /b /s " & Chr(34) & myPath & Chr(34)).StdOut.ReadAll, vbCrLf) '所有文档含子文件夹
- End With
- With ActiveSheet
- For i = 2 To .[B65536].End(xlUp).Row + 1
- Set rng = .Range("B" & i)
- If rng <> "" Then
- For j = 0 To UBound(fr)
- If InStr(fr(j), ".JPG") > 0 Then
- If Split(Split(fr(j), "")(UBound(Split(fr(j), ""))), ".")(0) = "" & rng.Value Then
- With ActiveSheet.Pictures.Insert(fr(j))
- .Top = rng.Offset(0, 3).Top + 2
- .Left = rng.Offset(0, 3).Left + 2
- .Height = rng.Offset(0, 3).Height
- '.Width = rng.Offset(0, 3).Width
- End With
- End If
- End If
- Next
- End If
- Next
- End With
- End Sub
- Sub Delshp()
- Dim shp As Shape
- For Each shp In ActiveSheet.Shapes
- If shp.Left < Range("F1").Left Then shp.Delete
- Next
- End Sub
复制代码 |
|