请参: '* +++++++++++++++++++++++++++++
'* Created By I Love You_Word!@ExcelHome 2005-4-5 05:12:35
'仅测试于System: Windows NT Word: 10.0 Language: 2052
'^The Code CopyIn [ThisDocument-ThisDocument]^'
'* -----------------------------Sub Example()
Dim MyFile As Object, MyFolder As Object, MyFolders As Object, F As Object
Dim FileCount As Integer, i As Integer, FileName As String
Set MyFolders = CreateObject("Scripting.FileSystemObject") '创建系统文件
'获得指定系统文件下的文件夹对象
Set MyFolder = MyFolders.GetFolder("E:\Test") '此处可更改路径,注意反斜杠
'获得指定文件夹下的实际WORD文件总数(去除了临时WORD文件)
For Each F In MyFolder.Files
If F.Type = "Microsoft Word Document" And VBA.InStr(F.Name, "~$") = 0 Then
' MsgBox F.Name
FileCount = FileCount + 1 '计数
End If
Next
For i = 1 To FileCount '在指定文件数量中循环
FileName = "E:\Test\" & i & ".Doc" '定义一个变量为文件名
If MyFolders.FileExists(FileName) = False Then '如果删除了某一个文件,则找不到
MsgBox "未找到" & FileName & "文件!" '提示
ActiveDocument.SaveAs FileName '以该文件名另存为
Exit Sub '退出程序
End If
Next
ActiveDocument.SaveAs "E:\Test\" & FileCount + 1 & ".Doc" '延续编号保存
End Sub
'---------------------- |