Ta muốn khi mở hộp BrowseForFolder thì sẽ duyệt ngay vào 1 thư mục do ta chỉ định trước VD : D:\Data\Pic chẳng hạn , không biết có thể đc không . Mong các bạn giúp đỡ![]()
Const WINDOW_HANDLE = 0
Const NO_OPTIONS = 0
Sub test()
Dim strPath As String, objFolder As Object, objShell As Object, objFolderItem As Object
On Error Resume Next
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.BrowseForFolder(WINDOW_HANDLE, "Select folder:", NO_OPTIONS,[B][COLOR=#ff0000] "D:\"[/COLOR][/B])
Set objFolderItem = objFolder.Self
strPath = objFolderItem.Path
MsgBox strPath
objFolder = Nothing: objShell = Nothing: objFolderItem = Nothing
End Sub
Ta muốn khi mở hộp BrowseForFolder thì sẽ duyệt ngay vào 1 thư mục do ta chỉ định trước VD : D:\Data\Pic chẳng hạn , không biết có thể đc không . Mong các bạn giúp đỡ![]()
Function BrowseForFolder(Optional ByVal DefaultPath As String) As String
With Application.FileDialog(msoFileDialogFolderPicker)
.AllowMultiSelect = False
If Len(DefaultPath) Then .InitialFileName = DefaultPath
If .Show Then BrowseForFolder = .SelectedItems(1)
End With
End Function
Sub Main()
Dim strFolder As String
strFolder = BrowseForFolder("[COLOR=#ff0000]D:\Excel[/COLOR]")
If Len(strFolder) Then MsgBox strFolder
End Sub


