Build an array of filenames and perform operation on each file:   Return to List

Public Sub Main()
Dim FileArray() As String, ffile As String, Count As Integer
Count = 0

' Navigate to a particular folder
With Dialogs(wdDialogFileOpen)
    .Name = "*.*"
    .Show
End With

' Get the initial filename
ffile = Dir("*.*")
ReDim FileArray(Count)    ' 0 based array -- dimensioning for 1 entry in the array
FileArray(Count) = LCase(ffile)
Count = 1
Do While ffile <> ""
    ffile = Dir()
    If ffile <> "." And ffile <> ". ." Then
        ReDim Preserve FileArray(Count)' Resizing array dynamically
        FileArray(Count) = LCase(ffile)
        Count = Count + 1
    End If
Loop

' Now we'll loop through the file array performing desired operations.
For i = LBound(FileArray()) To UBound(FileArray())
    Documents.Open(FileArray(i))
    ' Do whatever to the file
    ActiveDocument.Close(wdSaveChanges)
Next
Btn = MsgBox("There were" & Str(Count + 1) & " files modified.", vbOKOnly, " Results")
FINAL_EXIT:
End Sub



Note to Webmaster