gpt4 book ai didi

vba - 用 VBA 打开文件夹

转载 作者:行者123 更新时间:2023-12-04 21:56:27 34 4
gpt4 key购买 nike

有人可以帮我处理这段代码吗?
如何打开现有文件夹?

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 function :

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

关于vba - 用 VBA 打开文件夹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43803385/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com