Results 1 to 6 of 6
  1. #1
    5 Star Lounger
    Join Date
    Jul 2001
    Location
    Terneuzen, Netherlands
    Posts
    895
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Believe me, I did search but couldn't find exactly what I was looking for... (so i probably didn't search well enough because I'm sure this must be out there...)

    I'd like to be able to present a dialog that allows the user to pick a folder.

    Only two requirements:
    (1) The selected path should be available in a variable after the call (so I can use it)
    (2) I'd like to be able to specify a default folder before the call.

    Now I have seen code that allows one to specify an 'initial folder' but it appeared that this is used as TOP-folder and the user is not allowed to go above that. I don't want this; the default folder should come up but the user should be free to browse anywhere.

    I think the "Commondialog" might help me but on the net I'm drowning in apps that use it but all just a little different than what I'm looking for. Just hoping someone has this in a "library or routines" or so and would like to share (oh, by the way, I need to use this in my Excel2003 VBA app)

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

  3. #3
    5 Star Lounger
    Join Date
    Jul 2001
    Location
    Terneuzen, Netherlands
    Posts
    895
    Thanks
    0
    Thanked 0 Times in 0 Posts
    [quote name='HansV' post='785036' date='17-Jul-2009 11:45']See [VBnet Callbacks] SHBrowseForFolder: Pre-selecting Folders using a Browse Callback.[/quote]

    Oops... that looks complex. I'm OK to put my theeth in here a bit and see what I can get. I'm making progress but cannot start testing as I get an error on this line:

    .hOwner = Me.hWnd

    In the BrowseForFolderByPath function. Looks like I need the handle for the current window in VBA... not sure why yet. Is there no one who has already converted this to VBA maybe?

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    Or much easier:

    Code:
    Public Function BrowseFolder(ByVal strFolder As String) As String
      If Not Right(strFolder, 1) = "\" Then
    	strFolder = strFolder & "\"
      End If
      With Application.FileDialog(msoFileDialogFolderPicker)
    	.InitialFileName = strFolder
    	If .Show = True Then
    	  BrowseFolder = .SelectedItems(1)
    	End If
      End With
    End Function
    Use like this:

    Code:
    Dim strOldPath As String
    Dim strNewPath As String
    strOldPath = "C:\Program Files"
    strNewPath = BrowseFolder(strOldPath)
    If Not strNewPath = "" Then
      ...
    End If

  5. #5
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    I've posted a much simpler solution in the meantime, but for what it's worth, here is a (zipped) workbook that demonstrates the approach using callbacks.
    Attached Files Attached Files

  6. #6
    5 Star Lounger
    Join Date
    Jul 2001
    Location
    Terneuzen, Netherlands
    Posts
    895
    Thanks
    0
    Thanked 0 Times in 0 Posts
    [quote name='HansV' post='785364' date='20-Jul-2009 11:28']I've posted a much simpler solution in the meantime, but for what it's worth, here is a (zipped) workbook that demonstrates the approach using callbacks.[/quote]

    I like the short code; it does work fine and even tracks the folder history.

    The BrowseDemo has a nicer dialog box (but that's my opinion); no history however and works with a form to set the initial dir. I'm sure this can be re-worked but with the first approach working, I'm very happy (again).


    (I wouldn't know where I'd be without the help in this board. Hans, special thanks to you!)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •