0
首先,我必須說,我在一臺安裝了很少引用且根本沒有Office的計算機上運行代碼。VBA - 返回Shell explorer當前路徑,然後關閉它
我需要用Shell
命令打開一個「explorer.exe」實例,瀏覽文件夾,輸入一個選定的(或新創建的),最後點擊MsgBox
(同時彈出)上的「Ok」關閉Shell
並將選定的文件夾路徑返回給變量。
我不知道如何做到這一點。當我使用CurDir
時,我最終得到的文件夾不是選定的文件夾。使用
代碼(沒有工作):
Sub BrowseForFolder()
ActualDir = "D:\"
Call Shell("C:\Windows\explorer", ActualDir, 1)
If Msgbox("Browse into folder or create a new one and then browse into it, then click ok", vbOkOnly, "Browse") = vbOk Then
' here should be the command to return the path. The following doesn't work since it returns always "D:\"
ActualDir = CurDir
End If
' Here I have to close the Shell - I have no idea what to write to do it
End Sub
這是錯誤的方法:改爲檢查[Shell.BrowseForFolder](http://msdn.microsoft.com/en-us/library/windows/desktop/bb774065(v = vs.85).aspx)。你在使用[tag:VBA]還是[tag:VBScript]? –
我正在使用vba。我現在就給它一個鏡頭,讓你知道它是否有效 – Noldor130884
沒有Office,那麼VBA在哪個環境下?你可以從'應用程序'有更好的設施。 –