M
Matt Williamson
I wrote this routine to delete all of the footers in all of the documents
under a specific folder. It works fine, but requires the document to display
for every iteration of the loop. Is there a faster way to do this? I have to
run this against thousands of files.
I tried Setting the visible property of Document.open to false but then it's
not able to access the activedocument object to manipulate it.
Sub DeleteAllFooters()
Dim sStartFolder As String
Dim i As Long, j As Long
sStartFolder = "c:\word docs"
If Len(sStartFolder) = 0 Then
'Ask the user to select a folder
With Dialogs(wdDialogCopyFile)
'User selected a directory
If .Display Then
sStartFolder = .Directory
Else
'User chose Cancel
Exit Sub
End If
End With
End If
Application.Visible = False
Application.DisplayAlerts = wdAlertsNone
With Application.FileSearch
.LookIn = sStartFolder
.SearchSubFolders = True
.FileType = msoFileTypeWordDocuments
.Execute
For i = 1 To .FoundFiles.Count
Debug.Print .FoundFiles(i)
Documents.Open .FoundFiles(i)
For j = 1 To ActiveDocument.Sections.Count
With ActiveDocument.Sections(j)
.Footers(wdHeaderFooterFirstPage).Range.Delete
.Footers(wdHeaderFooterPrimary).Range.Delete
End With
Next j
Documents.Close wdSaveChanges
Next i
End With
End Sub
TIA
Matt
under a specific folder. It works fine, but requires the document to display
for every iteration of the loop. Is there a faster way to do this? I have to
run this against thousands of files.
I tried Setting the visible property of Document.open to false but then it's
not able to access the activedocument object to manipulate it.
Sub DeleteAllFooters()
Dim sStartFolder As String
Dim i As Long, j As Long
sStartFolder = "c:\word docs"
If Len(sStartFolder) = 0 Then
'Ask the user to select a folder
With Dialogs(wdDialogCopyFile)
'User selected a directory
If .Display Then
sStartFolder = .Directory
Else
'User chose Cancel
Exit Sub
End If
End With
End If
Application.Visible = False
Application.DisplayAlerts = wdAlertsNone
With Application.FileSearch
.LookIn = sStartFolder
.SearchSubFolders = True
.FileType = msoFileTypeWordDocuments
.Execute
For i = 1 To .FoundFiles.Count
Debug.Print .FoundFiles(i)
Documents.Open .FoundFiles(i)
For j = 1 To ActiveDocument.Sections.Count
With ActiveDocument.Sections(j)
.Footers(wdHeaderFooterFirstPage).Range.Delete
.Footers(wdHeaderFooterPrimary).Range.Delete
End With
Next j
Documents.Close wdSaveChanges
Next i
End With
End Sub
TIA
Matt