Sub P_Sample004()
Dim myFileName As String
myFileName = Application.InputBox(Prompt:= _
"請輸入檔案名稱、資料夾名稱的完整路徑", Title:="確認存在")
If Len(Dir(myFileName, vbDirectory)) > 0 Then
If (GetAttr(myFileName) And vbDirectory) = vbDirectory Then
MsgBox "所指定之資料夾存在。"
Else
MsgBox "所指定之檔案存在。"
End If
Else
MsgBox "所指定之檔案或是目錄不存在。"
End If
End Sub
Sub P_Sample003()
Dim myPath As String
Dim myFileName As String
Dim i As Long
myPath = ThisWorkbook.Path & "\" '任意的資料夾
myFileName = Dir(myPath, 0)
Do While Len(myFileName) > 0
Debug.Print myPath & myFileName
myFileName = Dir()
Loop
End Sub