|
Option Compare Text
Option Explicit
Sub test()
Dim br(), i&, j&, r&, f As Object, ff As Object, p$, dic As Object, vKey, pic As Picture
Application.ScreenUpdating = False
Set dic = CreateObject("Scripting.Dictionary")
p = ThisWorkbook.Path & "\41900110005\"
For Each ff In CreateObject("Scripting.FileSystemObject").GetFolder(p).subfolders
dic(ff.Name) = Empty: r = 0: Erase br
For Each f In CreateObject("Scripting.FileSystemObject").GetFolder(ff.Path).Files
If f.Name Like "*.jpg" Then
r = r + 1
ReDim Preserve br(1 To r)
br(r) = f.Path
End If
Next
dic(ff.Name) = transArrToRow(br, 2, 1, UBound(br))
Next
ActiveSheet.Cells.Delete
r = 0: Columns("A:B").ColumnWidth = 36.75
For Each vKey In dic.keys
r = r + 1
Cells(r, 1) = vKey
br = dic(vKey)
For i = 1 To UBound(br)
r = r + 1
Rows(r).RowHeight = 148.5
For j = 1 To UBound(br, 2)
If Len(br(i, j)) Then
Set pic = ActiveSheet.Pictures.Insert(br(i, j))
pic.ShapeRange.LockAspectRatio = msoFalse
pic.Placement = xlMoveAndSize
With Cells(r, j)
pic.Left = .Left + 2: pic.Top = .Top + 2
pic.Height = .Height - 4: pic.Width = .Width - 4
End With
End If
Next j
Next i
Next
Application.ScreenUpdating = True
Beep
End Sub
Function transArrToRow(ByVal ar, ByVal iCutNum&, _
ByVal iStartCol&, ByVal iEndCol&) As Variant()
Dim br, j&, n&, y&, x&, iColSize&
If iStartCol < LBound(ar) Then iStartCol = LBound(ar)
If iEndCol > UBound(ar) Then iEndCol = UBound(ar)
n = -(Int(-(iEndCol - iStartCol + 1) / iCutNum))
iColSize = IIf(iEndCol - iStartCol + 1 < iCutNum, iEndCol - iStartCol + 1, iCutNum)
ReDim br(1 To n, 1 To iColSize)
n = 0
For j = iStartCol To iEndCol
n = n + 1
y = -Int(-n / iCutNum)
x = IIf(n Mod iCutNum = 0, iCutNum, n Mod iCutNum)
br(y, x) = ar(j)
Next j
transArrToRow = br
End Function
|
评分
-
2
查看全部评分
-
|