Creating an Array of Filenames (nice for looping through later):   Return to List

Public Sub Main()
    Dim FileArray() As String, ffile As String, Count As Integer
    Count = 0
    With Dialogs(wdDialogFileOpen)
        .Name = "*.*"
        .Show
    End With
    ffile = Dir("*.*")
    ReDim FileArray(Count)
    FileArray(Count) = LCase(ffile)
    Count = 1
    Do While ffile <> ""
        ffile = Dir()
        If ffile <> "." And ffile <> ". ." Then
            ReDim Preserve FileArray(Count)
            FileArray(Count) = LCase(ffile)
            Count = Count + 1
        End If
    Loop

    For i = LBound(FileArray()) To UBound(FileArray())
        Selection.InsertAfter Text:=FileArray(i) + Chr(13)
        Selection.ExtendMode = False
        Selection.MoveRight Unit:=wdCharacter, Count:=1
    Next

    Btn = MsgBox("There were" + Str(Count - 1) + " files listed.", vbOKOnly, " Results")
FINAL_EXIT:
End Sub

See also:
Array Converted to Delimited Text String
Delimited Text to an Array (similar to Split())
Determining Upper & Lower Array Bounds
Erasing an Array (removing all the elements)
Feed an Array into a New Document (del dupes)
Filename Array from Active Directory
QuickSort routine
QuickSort (Fast!!) (Multidimensional on 2 dims)
QuickSort (Fast!!) (Multidimensional on 3 dims)
QuickSort (Fast!!) (Single Dimension)
Removing Duplicates from an Array
SQL Query Results placed in an Array
Using Split() function to create Array



Note to Webmaster