|
- Sub ListSubFolder() 'MXG825 2012-6-9
- Dim strPath As String, strTmp As String
- Dim oldTmp As String, newTmp As String
- strPath = ThisWorkbook.Path & ""
- If Dir(strPath & "汇总", 16) = Empty Then '汇总文件夹是否存在
- MkDir strPath & "汇总" '建一个
- End If
- strTmp = Dir(strPath & "*", vbDirectory) '列出所有目录
- Do While strTmp <> "" '历遍全部文件夹
- '以vbDirectory属性来调用Dir时,不能连续地返回子目录,所以使用GetAttr来判断结果是否为目录
- If GetAttr(strPath & strTmp) And vbDirectory Then
- On Error GoTo NextTmp '防文件不存在 跳转词句
- If InStr(1, "汇总,提取.xls..", strTmp) = 0 Then '剔除 汇总文件夹 和提取 工作薄
- oldTmp = strPath & strTmp & "\汇总\汇总.xls" '原文件路径
- newTmp = strPath & "\汇总" & strTmp & ".xls" '新文件路径
- FileCopy oldTmp, newTmp '复制 重命名文件
- 'Debug.Print strPath & strTmp
- End If
- End If
- NextTmp:
- strTmp = Dir
- Loop
- End Sub
复制代码
|
|