View Full Version : Solved: Question re: Browse For Folder KBase article
dragon
03-28-2007, 09:51 AM
Hello everyone, Is it possible to amend the code in Ken Puls' Browse For Folder KBase article (http://vbaexpress.com/kb/getarticle.php?kb_id=284)( 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
mdmackillop
03-28-2007, 10:24 AM
The code uses a built-in object. I doubt it can be modified.
lucas
03-28-2007, 10:37 AM
See if you can use this one..it doesn't have an add new folder button. Example macro1 included for example useage:
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
dragon
03-28-2007, 11:01 AM
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?
lucas
03-28-2007, 11:05 AM
Here is another method(attached)it is more flexible on starting path. see comments in code
dragon
03-28-2007, 11:27 AM
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.
lucas
03-28-2007, 11:37 AM
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:
' 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
lucas
03-28-2007, 11:41 AM
I'll just post it...see attached
credit to ken Puls for this dialog box
dragon
03-28-2007, 12:33 PM
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
Ivan F Moala
03-28-2007, 01:49 PM
Hello everyone, Is it possible to amend the code in Ken Puls' Browse For Folder KBase article (http://vbaexpress.com/kb/getarticle.php?kb_id=284)( 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
mdmackillop
03-28-2007, 02:32 PM
The code uses a built-in object. I doubt it can be modified.footinmout
lucas
03-28-2007, 05:27 PM
.:whistle:
lucas
03-28-2007, 08:13 PM
I had never considered it until Ivan dropped by..
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.