|
本帖最后由 yxbaju 于 2018-10-13 14:46 编辑
Sub fenlei()
'按照现有的三个文件夹分类,未写创建新文件夹代码(不删除创建好的即可),未写防止表名重复的文件移动(会报错),如需要请修改代码
Dim sPath$, sNewpath$, sFilename$, sFullname$, rng As Range
Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
sPath = ThisWorkbook.Path & "\"
sFilename = Dir(sPath & "*.xlsx")
Do While sFilename <> ""
If sFilename <> ActiveWorkbook.Name Then
sFullname = sPath & sFilename
Set rng = GetObject(sFullname).Worksheets(1).Cells.SpecialCells(xlCellTypeLastCell)
sNewpath = Left(sPath, Len(sPath) - Len(Split(sPath, "\")(UBound(Split(sPath, "\")) - 1)) - 2) & "\"
If rng.Column = 11 Then Workbooks(sFilename).Close False: fso.movefile sFullname, sNewpath & "第一种表格\": GoTo 1
If rng.Column = 15 Then Workbooks(sFilename).Close False: fso.movefile sFullname, sNewpath & "第二种表格\": GoTo 1
If rng.Column = 45 Then Workbooks(sFilename).Close False: fso.movefile sFullname, sNewpath & "第三种表格\": GoTo 1
End If
1:
sFilename = Dir
Loop
MsgBox "完成"
End Sub
|
|