VBA/Excel/Access/Word/Forms/Dir
Версия от 16:33, 26 мая 2010; (обсуждение)
Содержание
Dir() Returns a string representing the name of a file or directory with specified pattern.
Sub strDemo19()
Debug.Print Dir("C:\Windows\*.ini")
End Sub
Get Directory by using the Dir function
Sub DirDemo2()
MsgBox Dir
End Sub
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
Use Dir function to get the file directory
Sub DirDemo()
Dim FType As String
FType = "*.xls"
MsgBox Dir(FType)
End Sub
Validate the file path
Function ValidPath() As Boolean
Dim fPath As String
fPath = "c:\"
If Dir(fPath, vbDirectory) = "" Or fPath = "" Then
ValidPath = False
Else
ValidPath = True
End If
End Function