|
- Dim arrFiles()
- Dim cntFiles%
- Public Sub ListAllFiles()
- Dim myDialog As FileDialog, oDoc As Document, oSec As Section
- Dim oFile As Variant, myRange As Range
- On Error Resume Next
- Dim strPath$
- Dim i%
- Dim fso As New FileSystemObject, fd As Folder
- strPath = ActiveDocument.Path & Application.PathSeparator '········
- ReDim arrFiles(1 To 1000)
- cntFiles = 0
- Set fd = fso.GetFolder(strPath)
- SearchFiles fd
- ReDim Preserve arrFiles(1 To cntFiles)
- For i = 1 To cntFiles
- Set oDoc = Word.Documents.Open(FileName:=arrFiles(i), Visible:=False)
- For Each oSec In oDoc.Sections '文档的节中循环
- Set myRange = oSec.Headers(wdHeaderFooterPrimary).Range
- myRange.Delete '删除页眉中的内容
- myRange.ParagraphFormat.Borders(wdBorderBottom).LineStyle = wdLineStyleNone '段落下边框线
- Set myRange = oSec.Footers(wdHeaderFooterPrimary).Range
- myRange.Delete '删除页脚中的内容
- Next
- oDoc.Close True
- Next i
- End Sub
- Sub SearchFiles(ByVal fd As Folder)
- Dim fl As File
- Dim sfd As Folder
- For Each fl In fd.Files
- cntFiles = cntFiles + 1
- If cntFiles > UBound(arrFiles) Then ReDim Preserve arrFiles(1 To cntFiles + 1000)
-
- m = Split(fl.Name, ".")(1)
- If m = "doc" Or m = "docx" Then
- arrFiles(cntFiles) = fl.Path
- End If
- arrFiles(cntFiles) = fl.Path
- Next fl
- If fd.SubFolders.Count = 0 Then Exit Sub
- For Each sfd In fd.SubFolders
- SearchFiles sfd
- Next
- End Sub
复制代码 |
|