|
请楼主打包备份文件后应用下面的宏:(2003版通过,不知在2007版中管不管事)
Sub test()
On Error Resume Next
Dim fd As FileDialog, i As Long, doc As Document, p As String
Set fd = Application.FileDialog(msoFileDialogFolderPicker)
If fd.Show = -1 Then p = fd.SelectedItems(1) Else Exit Sub
Set fd = Nothing
If MsgBox("Are you sure to process the folder " & p & " ?" & vbCr & "是否处理文件夹 " & p & " ?", vbYesNo + vbExclamation, "循环遍历文件夹") = vbNo Then Exit Sub
With Application.FileSearch
.LookIn = p
.SearchSubFolders = True
.FileName = "*.docx"
If .Execute > 0 Then
For i = .FoundFiles.Count To 1 Step -1
Set doc = Documents.Open(FileName:=.FoundFiles(i))
'''删除段落首尾空格及空行()
With doc.Content.Find
.Execute findtext:="^l", ReplaceWith:="^p", Replace:=wdReplaceAll
.Execute findtext:="^13", ReplaceWith:="^p", Replace:=wdReplaceAll
End With
Selection.WholeStory
CommandBars.FindControl(ID:=122).Execute
CommandBars.FindControl(ID:=123).Execute
Dim k As Paragraph
For Each k In doc.Paragraphs
If Len(k.Range) = 1 Then k.Range.Delete
Next
'
Dim j As String, newName As String, oldName As String
j = doc.Paragraphs(1).Range.Text
j = Left(j, Len(j) - 1)
newName = doc.Path & "\" & j & ".docx"
oldName = doc.FullName
doc.Close savechanges:=wdDoNotSaveChanges '关闭文档不保存任何修改
Name oldName As newName '文件重命名
''''''''''
Next i
MsgBox "Complete! There were " & .FoundFiles.Count & " file(s) processed." & vbCr & "处理完毕!共处理 " & .FoundFiles.Count & " 个文件!", vbOKOnly + vbExclamation, "循环遍历文件夹"
Else
MsgBox "There were no files found." & vbCr & "未发现文件!", vbOKOnly + vbCritical, "循环遍历文件夹"
End If
End With
End Sub |
|