Get the file names : Dir « Forms « VBA / Excel / Access / Word






Get the file names

 

Sub FileNames()
  Dim FName As String
  Dim FNames() As String
  Dim FType As String
  Dim i As Integer
  
  FType = "*.xls"
  FName = Dir(FType)
  Do Until FName = ""
    i = i + 1
    ReDim Preserve FNames(1 To i)
    FNames(i) = FName
    FName = Dir
  Loop
  If i <> 0 Then
    For i = 1 To UBound(FNames)
      MsgBox FNames(i)
    Next i
  End If
End Sub

 








Related examples in the same category

1.Dir() Returns a string representing the name of a file or directory with specified pattern.
2.Use Dir function to get the file directory
3.Get Directory by using the Dir function
4.Validate the file path