|
插入文件夹内图片并5个为一排
- Option Compare Text
- Sub StoPic()
- Dim Fso, ff, f, prr(), r, c, i, j, k, p, q
- Dim Pl, Pt, Pw, Ph, Img 'As ImageFile
- Set Img = CreateObject("WIA.ImageFile")
- On Error Resume Next
- Set Fso = CreateObject("scripting.filesystemobject")
- Set ff = Fso.Getfolder(ThisWorkbook.Path & "\案例")
- ReDim prr(1 To ff.Files.Count)
- p = 0
- For Each f In ff.Files
- If InStr(f, ".JPG") Then
- p = p + 1
- prr(p) = f
- End If
- Next
- i = 0
- With Sheet1
- Call delshp
- For q = 1 To p
- Img.LoadFile prr(q)
- Pw = Img.Width / 2
- Ph = Img.Height / 2
- c = q Mod 5
- If c = 1 Then
- i = i + 1
- r = 2 + (i - 1) * 21
- Else
- If c = 0 Then c = 5
- End If
- Pl = (c - 1) * (Pw + 10)
- Pt = .Range("A" & r).Top
- .Shapes.AddPicture prr(q), True, True, Pl, Pt, Pw, Ph
- Next
- End With
- MsgBox "ok!"
- End Sub
- Sub delshp()
- Dim shp As Shape
- For Each shp In Sheet1.Shapes
- If shp.Type <> 8 And shp.Type <> 12 Then
- shp.Delete
- End If
- Next
- End Sub
复制代码
楼主附件似乎有病毒,请自行测试
|
|