返回列表 上一主題 發帖

[發問] Dir 匯出指令可否排除 目錄呢?

回復 3# prin.huang


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

TOP

        靜思自在 : 待人退一步,愛人寬一寸,就會活得很快樂。
返回列表 上一主題