用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
使用Shellfunction :
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