Databases Reference
In-Depth Information
BrowseForDirectory = ""
End If
End If
End Function
2.8
SETTING THE STARTING DIRECTORY FOR A USER
TO BROWSE FROM
The previous “browse for directory” example works well enough for most purposes, but it is
missing one key feature: the ability to set the starting directory from which the user is to start
browsing from. In some applications, this may not be that critical. It becomes a huge convenience
factor when the directory of choice is several layers deep, buried within numerous subdirectories.
The end user will invariably get tired of clicking through all the top-level directories, especially
when all the directories that would most likely be chosen are buried deep within a complex path
structure.
It would seem that setting such a starting point for the “Browse for Directory” dialog box
would be a trivial matter, but in fact it is not. This is because Microsoft Office VBA does not
support the “AddressOf” operator that is required to tell Windows where the “call back” functions
are. The following workaround utilizes methods first published by Ken Getz and Michael Kaplan
in the May 1998 issue of Microsoft Office & Visual Basic for Applications Developer .
Even if the command ChDir "c:\temp" is placed at the beginning of the BrowseFor-
Directory function, the “Browse for Directory” dialog box will still start at the point “My
Computer.” The code for the workaround to fix this deficiency within Microsoft Excel is far too
long to publish within this chapter (in fact, it encompasses an entire module “BrowseSpecDir”),
but is listed within Appendix A.
In addition to the ability to pick the starting directory, numerous other options can be selected
when utilizing the “Browse for Folder” dialog box. They include allowing direct entry of file paths
(not a good idea), validating entries (good idea), showing the status bar and associated text, showing
files contained within the directories, utilizing the newer “Browse for Folder” dialog box style, and
whether to center the “Browse for Folder” dialog box on the screen. The next function, Steroid-
Browse , makes use of the code in module BrowseSpecDir to utilize the additional options
available when utilizing the “Browse for Folder” dialog box just discussed.
Function SteroidBrowse(ByVal initialpath$, ByVal
AllowDirectEntry As Boolean, ByVal ValidateEntry As Boolean, _
ByVal ShowStatusText As Boolean, ByVal ShowFilesToo As Boolean,
ByVal UseNewDialogStyle As Boolean, _
ByVal CenterOnScreen As Boolean) As String
'Set up Browse Options via Boolean Flags
Dim RetStr As String, Flags As Long, DoCenter As Boolean
Flags = BIF_RETURNONLYFSDIRS
If AllowDirectEntry = True Then
Flags = Flags + BIF_EDITBOX
End If
If ValidateEntry = True Then
Flags = Flags + BIF_VALIDATE
End If
If ShowStatusText = True Then
Flags = Flags + BIF_STATUSTEXT
Search WWH ::




Custom Search