用vba:将一群png图片分到个文件夹,保证文件夹内文件数不超过100
时间: 2024-06-03 20:07:02 浏览: 177
VBA excel实现合并文件夹及子文件夹内的所有excel文件
Sub SplitPNG()
Dim folderPath As String
folderPath = "C:\Users\username\Desktop\PNG" '修改为实际路径
Dim FSO As Object
Set FSO = CreateObject("Scripting.FileSystemObject")
Dim folder As Object
Set folder = FSO.GetFolder(folderPath)
Dim file As Object
Dim i As Long
i = 1
Dim j As Long
j = 1
Dim newFolder As Object
Set newFolder = FSO.CreateFolder(folderPath & "\Folder1")
For Each file In folder.Files
If Right(file.Name, 3) = "png" Then
If i > 100 Then
j = j + 1
Set newFolder = FSO.CreateFolder(folderPath & "\Folder" & j)
i = 1
End If
FSO.MoveFile file.Path, newFolder.Path & "\" & file.Name
i = i + 1
End If
Next
End Sub
阅读全文