BrowseForFolder(Me.hwnd, "選擇相片保存位置", , NEWFOLDER)
不知道是不是這個,你試下.
Private Sub BrowseCmd_Click() Dim Path As String Path = BrowseForFolder(Me, 0, "Select Project's Location :") If (Trim(Path) <> "") Then TextTarget.Text = Path End If ComAdd1.Enabled = True: ComAdd2.Enabled = True ComLess1.Enabled = True: ComLess2.Enabled = True End Sub
Public Declare Function lstrcat Lib "kernel32" Alias "lstrcatA" (ByVal lpString1 As String, ByVal lpString2 As String) As Long Public Declare Function SHGetPathFromIDList Lib "shell32" (ByVal pidList As Long, ByVal lpBuffer As String) As Long Public Declare Function SHBrowseForFolder Lib "shell32" (lpbi As BrowseInfo) As Long Public Declare Sub CoTaskMemFree Lib "ole32.dll" (ByVal hMem As Long) Public Type BrowseInfo hWndOwner As Long pIDLRoot As Long pszDisplayName As Long lpszTitle As Long ulFlags As Long lpfnCallback As Long lParam As Long iImage As Long End Type Public Const BIF_RETURNONLYFSDIRS = &H1 Public Const MAX_PATH_LEN = (256 - 1) Public Function BrowseForFolder(ByRef owner As Form, ByRef StartLoc As Long, ByRef Title As String) As String Dim lpbi As BrowseInfo Dim lpIDList As Long Dim sPath As String Dim iNull As Integer Dim code As Integer, Description As String On Error GoTo ErrorHandling With lpbi 'Set the owner window .hWndOwner = owner.hwnd ' Specific Root Location .pIDLRoot = StartLoc 'lstrcat appends the two strings and returns the memory address .lpszTitle = lstrcat(Title, "") 'Return only if the user selected a directory .ulFlags = BIF_RETURNONLYFSDIRS End With lpIDList = SHBrowseForFolder(lpbi) If lpIDList Then sPath = String$(MAX_PATH_LEN, 0) 'Get the path from the IDList Call SHGetPathFromIDList(lpIDList, sPath) 'free the block of memory Call CoTaskMemFree(lpIDList) iNull = InStr(sPath, vbNullChar) If iNull Then sPath = Left$(sPath, iNull - 1) End If End If BrowseForFolder = sPath Exit Function ErrorHandling: code = Err.Number Description = Err.Description MsgBox "BrowseForFolder" & " " & code & " " & Description Resume Next End Function