In Word 7.0, under Tools, Options, File Locations tab, there is a dialog that comes up to define the folder containing certain types of files. This dialog allows folder selection only, not file selection. Is this acessible through VB somehow? Is it a common dialog that I can get to?If not, is there a simple method to create this type of dialog?
The standard Common Dialog is unable to create this dialog. However, anAPI call to the shell is able to do it. Add the code to your project, andthen call the routine like so:
Dim sPath as StringsPath = fnBrowseForFolder(Me.hWnd, “Select Output Directory”)Me refers to a form, so you can specify a particular form if you wish. Thedialog will approximately center itself within the borders of the form, soyou may want to pick your MDI frame if you are using one.
Option ExplicitPrivate Type BrowseInfo hWndOwner As Long pIDLRoot As Long pszDisplayName As Long lpszTitle As Long ulFlags As Long lpfnCallback As Long lParam As Long iImage As LongEnd TypePrivate Const BIF_RETURNONLYFSDIRS = 1Private Const MAX_PATH = 260Private Declare Function lstrcat Lib “kernel32” Alias “lstrcatA” _ (ByVal lpString1 As String, ByVal lpString2 As String) As LongPrivate Declare Function SHBrowseForFolder Lib “shell32” _ (lpbi As BrowseInfo) As LongPrivate Declare Function SHGetPathFromIDList Lib “shell32″ _ (ByVal pidList As Long, ByVal lpBuffer As String) As Long” fnBrowseForFolder” This function will create the directory browser’ window common to other applications.’Public Function fnBrowseForFolder(hWndOwner As Long, sPrompt As String) AsString Dim iNull As Integer Dim lpIDList As Long Dim lResult As Long Dim sPath As String Dim udtBI As BrowseInfo Dim iPos As Integer With udtBI .hWndOwner = hWndOwner .lpszTitle = lstrcat(sPrompt, “”) .ulFlags = BIF_RETURNONLYFSDIRS End With lpIDList = SHBrowseForFolder(udtBI) sPath = Space$(512) If lpIDList Then lResult = SHGetPathFromIDList(lpIDList, sPath) If lResult Then iPos = InStr(sPath, Chr$(0)) sPath = Left$(sPath, iPos) Else sPath = “” End If End If fnBrowseForFolder = sPathEnd Function