Consulting

Results 1 to 13 of 13

Thread: Solved: Question re: Browse For Folder KBase article

  1. #1
    VBAX Regular
    Joined
    Jun 2005
    Posts
    51
    Location

    Solved: Question re: Browse For Folder KBase article

    Hello everyone, Is it possible to amend the code in Ken Puls' Browse For Folder KBase article ( I.D. 284), so that the "Make New Folder" button does not appear on the browse for folder dialog box? I adapted the code some time ago to enable users to select a folder to file documents directly from Word, Excel and Outlook to a network drive, but haven't been able to figure out how to get rid of the button, and it bugs me from time to time when I see it. Thanks in anticipation

    Edit: MD Link added
    Last edited by dragon; 03-28-2007 at 10:02 AM.

  2. #2
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    The code uses a built-in object. I doubt it can be modified.
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  3. #3
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    See if you can use this one..it doesn't have an add new folder button. Example macro1 included for example useage:
    [VBA]Option Compare Text
    Option Explicit

    Private Const BIF_RETURNONLYFSDIRS As Long = &H1
    Private Const BIF_DONTGOBELOWDOMAIN As Long = &H2
    Private Const BIF_RETURNFSANCESTORS As Long = &H8
    Private Const BIF_BROWSEFORCOMPUTER As Long = &H1000
    Private Const BIF_BROWSEFORPRINTER As Long = &H2000
    Private Const BIF_BROWSEINCLUDEFILES As Long = &H4000
    Private Const MAX_PATH As Long = 260

    Type BrowseInfo
    hOwner As Long
    pidlRoot As Long
    pszDisplayName As String
    lpszINSTRUCTIONS As String
    ulFlags As Long
    lpfn As Long
    lParam As Long
    iImage As Long
    End Type

    Type SHFILEOPSTRUCT
    hwnd As Long
    wFunc As Long
    pFrom As String
    pTo As String
    fFlags As Integer
    fAnyOperationsAborted As Boolean
    hNameMappings As Long
    lpszProgressTitle As String
    End Type

    Declare Function SHGetPathFromIDListA Lib "shell32.dll" ( _
    ByVal pidl As Long, _
    ByVal pszBuffer As String) As Long
    Declare Function SHBrowseForFolderA Lib "shell32.dll" ( _
    lpBrowseInfo As BrowseInfo) As Long

    Function BrowseFolder(Optional Caption As String = "") As String

    Dim BrowseInfo As BrowseInfo
    Dim FolderName As String
    Dim ID As Long
    Dim Res As Long

    With BrowseInfo
    .hOwner = 0
    .pidlRoot = 0
    .pszDisplayName = String$(MAX_PATH, vbNullChar)
    .lpszINSTRUCTIONS = Caption
    .ulFlags = BIF_RETURNONLYFSDIRS
    .lpfn = 0
    End With
    FolderName = String$(MAX_PATH, vbNullChar)
    ID = SHBrowseForFolderA(BrowseInfo)
    If ID Then
    Res = SHGetPathFromIDListA(ID, FolderName)
    If Res Then
    BrowseFolder = Left$(FolderName, InStr(FolderName, _
    vbNullChar) - 1)
    End If
    End If

    End Function

    Sub Macro1()
    Dim Path As String
    Dim Prompt As String
    Dim Title As String
    Path = BrowseFolder("Select A Folder")
    If Path = "" Then
    Prompt = "You didn't select a folder. The procedure has been canceled."
    Title = "Procedure Canceled"
    MsgBox Prompt, vbCritical, Title
    Else
    Prompt = "You selected the following path:" & vbNewLine & Path
    Title = "Procedure Completed"
    MsgBox Prompt, vbInformation, Title
    End If
    End Sub[/VBA]
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  4. #4
    VBAX Regular
    Joined
    Jun 2005
    Posts
    51
    Location
    Thanks lucas I think this will work, but one question - is it possible to get the browse for folder to open at a particular drive/folder instead of the default Desktop folder?

  5. #5
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    Here is another method(attached)it is more flexible on starting path. see comments in code
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  6. #6
    VBAX Regular
    Joined
    Jun 2005
    Posts
    51
    Location
    Thanks for the attachment lucas. I will have to play around with it and get back to you as I don't need the file names to appear on the form, only the folder names.

  7. #7
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    Look for this section of code in the module PopListBox and replace it with what I have here....no files listed. You may want to remove any references or dims for oFileSearch also:
    [VBA]' Set oFileSearch = Application.FileSearch
    ' With oFileSearch
    ' .LookIn = txtPath.Text
    ' .FileName = "*.*"
    ' If .Execute > 0 Then
    ' For i = 1 To .FoundFiles.Count
    ' sFileName = oFileSysObj.getfilename(.FoundFiles(i))
    lstFolders.AddItem 'sFileName 'add each file
    ' Next i
    ' End If
    ' End With[/VBA]
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  8. #8
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    I'll just post it...see attached
    credit to ken Puls for this dialog box
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  9. #9
    VBAX Regular
    Joined
    Jun 2005
    Posts
    51
    Location
    lucas thanks very much for the attachment. I think that's sorted everything out. (I've been a bit distracted since my last post due to a leaking radiator valve! - so didn't actually get around to trying to modify your code to remove references to file names myself). Anyway - thanks again

  10. #10
    VBAX Contributor Ivan F Moala's Avatar
    Joined
    May 2004
    Location
    Auckland New Zealand
    Posts
    185
    Location
    Quote Originally Posted by dragon
    Hello everyone, Is it possible to amend the code in Ken Puls' Browse For Folder KBase article ( I.D. 284), so that the "Make New Folder" button does not appear on the browse for folder dialog box? I adapted the code some time ago to enable users to select a folder to file documents directly from Word, Excel and Outlook to a network drive, but haven't been able to figure out how to get rid of the button, and it bugs me from time to time when I see it. Thanks in anticipation

    Edit: MD Link added
    You just need to modify

    BrowseForFolder(0, "Please choose a folder", 0, OpenAt)

    with

    BrowseForFolder(0, "Please choose a folder", BIF_NONEWFOLDERBUTTON, OpenAt)


    Where BIF_NONEWFOLDERBUTTON is Private Const BIF_NONEWFOLDERBUTTON As Long = &H200

    See here

    http://www.xcelfiles.com/Shell32_00.html
    Kind Regards,
    Ivan F Moala From the City of Sails

  11. #11
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Quote Originally Posted by mdmackillop
    The code uses a built-in object. I doubt it can be modified.
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  12. #12
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    .
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  13. #13
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    I had never considered it until Ivan dropped by..
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

Posting Permissions

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