View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Nate Oliver[_3_] Nate Oliver[_3_] is offline
external usenet poster
 
Posts: 71
Default set last used for getting directory

Did I miss something?

Yes, the function that Sub TesterIII() is calling, that being
BrowseForFolderShell().

Try the following:

'-------------------------------------------------------------------------
Public Function BrowseForFolderShell( _
Optional Hwnd As Long = 0, _
Optional sTitle As String = vbNullString, _
Optional BIF_Options As Long = &H20, _
Optional vRootFolder As Variant) As String

Dim objShell As Object
Dim objFolder As Object
Dim strFolderFullPath As String

Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell. _
BrowseForFolder(Hwnd, sTitle, BIF_Options, vRootFolder)

If (Not objFolder Is Nothing) Then
'// NB: If SpecFolder= 0 = Desktop then ....
On Error Resume Next
If IsError(objFolder.Items.Item.Path) Then _
strFolderFullPath = CStr(objFolder): GoTo GotIt
On Error GoTo 0
'// Is it the Root Dir?...if so change
If Len(objFolder.Items.Item.Path) 3 Then
strFolderFullPath = objFolder.Items.Item.Path & _
Application.PathSeparator
Else
strFolderFullPath = objFolder.Items.Item.Path
End If
Else
'// User cancelled
GoTo XitProperly
End If

GotIt:
BrowseForFolderShell = strFolderFullPath

XitProperly:
Set objFolder = Nothing
Set objShell = Nothing

End Function

Sub TesterIII()
'// Using String
'// This will not only limit the User to a specific Folder
Dim strFolder As String

Call BrowseForFolderShell(, , , CurDir)

If strFolder = vbNullString Then
MsgBox "You cancelled"
Else
MsgBox strFolder
End If

End Sub
'-------------------------------------------------------------------------

Regards,
Nate Oliver