|
Sub 批量处理文件及子目录()
Dim startfolder As String
startfolder = "D:\新建文件夹" '指定文件夹
Set folderlist = CreateObject("scripting.dictionary")
Set filelist = CreateObject("scripting.dictionary")
i = 1
kzm = ".doc"
folderlist.Add startfolder, ""
Do While folderlist.Count > 0
For Each FolderName In folderlist.keys
fname = Dir(FolderName, vbDirectory)
Do While fname <> ""
If fname <> ".." And fname <> "." Then
If GetAttr(FolderName & fname) And vbDirectory Then
folderlist.Add FolderName & fname & "", ""
Else
If LCase(Right(fname, Len(kzm))) = kzm Then
Documents.Open Filename:=FolderName & fname '打开文件
ActiveDocument.Save '保存文件
ActiveDocument.Close '关闭文件
End If
End If
End If
fname = Dir
Loop
folderlist.Remove (FolderName)
Next
Loop
MsgBox "完成"
End Sub
看看是否合适吧 |
|