簡體   English   中英

使用VBA打開文件夾

[英]Open folder with VBA

任何人都可以幫我這個代碼嗎?
如何打開現有文件夾?

Sub click button()
    Dim folderpath As String
    folderpath = "c:\"
    Dim rng As Range
    Set rng = Range(Selection.Address)
    Dim col As Range

    For Each col In rng.Rows
        If Dir(folderpath + CStr(col.Rows), vbDirectory) = "" Then
            Dim response
            response = MsgBox("Folder:" & col.Rows & " doesnt exist. Do you want to create it?", vbYesNo, "Folder")
            If response = vbYes Then
                MkDir (folderpath + CStr(col.Rows))
            End If 
        Else
            MsgBox "Folder:" & col.Rows & " exists"
        End If
    Next col
End Sub

使用Shell函數

Shell "C:\WINDOWS\explorer.exe """ & folderpath + CStr(col.Rows) & "", vbNormalFocus

在全:

Sub click button()
    Dim folderpath As String
    folderpath = "c:\"
    Dim rng As Range
    Set rng = Range(Selection.Address)
    Dim col As Range

    For Each col In rng.Rows
        If Dir(folderpath + CStr(col.Rows), vbDirectory) = "" Then
            Dim response
            response = MsgBox("Folder:" & col.Rows & " doesnt exist. Do you want to create it?", vbYesNo, "Folder")
            If response = vbYes Then
                MkDir (folderpath + CStr(col.Rows))
            End If 
        Else
            response = MsgBox("Folder:" & col.Rows & " exists. Do you want to open it?", vbYesNo, "Folder")
            If response = vbYes Then
                 Shell "C:\WINDOWS\explorer.exe """ & folderpath + CStr(col.Rows) & "", vbNormalFocus
            End if
        End If
    Next col
End Sub

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM