使用VBA打开文件夹

时间:2017-05-05 11:06:19

标签: excel vba excel-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

0 个答案:

没有答案