|
- Sub test1()
- Dim sPath As String, oFolder As Object, oFile As Object, bFilesExists As Boolean
- Dim Cel As Range, Shp As Shape, iRow As Integer, pCol As Integer
- sPath = "c:\testbatpic"
- If Dir(sPath, vbDirectory) = "" Then MsgBox "Not exists " & sPath: Exit Sub
- ActiveSheet.Pictures.Delete
- Application.ScreenUpdating = False
- With ActiveCell
- iRow = .Row - 1
- pCol = .Column
- End With
- For Each oFolder In CreateObject("Scripting.FileSystemObject").GetFolder(sPath).SubFolders
- bFilesExists = False
- For Each oFile In oFolder.Files
- If LCase(Right(oFile.Name, 4)) = ".jpg" Then
- If Not bFilesExists Then
- iRow = iRow + 1
- Cells(iRow, pCol) = oFolder.Name 'oFolder.Path
- bFilesExists = True
- End If
- iRow = iRow + 1
- Set Cel = Cells(iRow, pCol)
- Cel.Value = oFile.Name 'oFile.Path
- Set Shp = ActiveSheet.Shapes.AddPicture(oFile.Path, msoFalse, msoCTrue, Cel.Left, Cel.Top, Cel.Width, Cel.Height)
- Shp.Placement = xlMoveAndSize
- End If
- Next
- Next
- Set Cel = Nothing
- Set Shp = Nothing
- Application.ScreenUpdating = True
- End Sub
复制代码 |
|