Restrict to one folder (msoFileDialogFilePicker)

J

John J.

While using the Application.FileDialog(msoFileDialogFilePicker) code is it
possible to restrict the user's choice from one specific folder (or
underlying folder of this folder)?

Thank you.
John
 
S

S.Clark

Probably not with the MSO, but you can with the code after the folderis
selected.

Check what the path is, if not valid, then prompt them again?
 
P

Paul Shapiro

You can restrict the user from changing the folder using the Windows API
file dialog, but it's more work. You can find relevant code by searching or
post back if you want more info. I'm not sure it would still allow you to
change to subfolders, since the flag is called NoChangeDir.
 
J

John J.

I found the API-call which works but I haven't found the NoChangeDir
setting. Could you provide some more info about it? Thanks.
John
 
J

John J.

Thanks. Not exáctly what I had in mind since the user gets noticed a bit too
late. On the other hand, with this I could allow underlying folders.

John
 
P

Paul Shapiro

The Windows API call uses the OPENFILE structure, which has a Flags
attribute. NoChangeDir is one of the bits in that flags setting. You can
combine any of the flag options. Here are the details:

Type OPENFILENAME
lStructSize As Long
hwndOwner As Long
hInstance As Long
lpstrFilter As String
lpstrCustomFilter As Long
nMaxCustrFilter As Long
nFilterIndex As Long
lpstrFile As String
nMaxFile As Long
lpstrFileTitle As String
nMaxFileTitle As Long
lpstrInitialDir As String
lpstrTitle As String
Flags As Long
nFileOffset As Integer
nFileExtension As Integer
lpstrDefExt As String
lCustrData As Long
lpfnHook As Long
lpTemplateName As Long
End Type

Const OFN_ALLOWMULTISELECT As Long = &H200
Const OFN_CREATEPROMPT As Long = &H2000
Const OFN_EXPLORER As Long = &H80000
Const OFN_FILEMUSTEXIST As Long = &H1000
Const OFN_HIDEREADONLY As Long = &H4
Const OFN_NOCHANGEDIR As Long = &H8
Const OFN_NODEREFERENCELINKS As Long = &H100000
Const OFN_NONETWORKBUTTON As Long = &H20000
Const OFN_NOREADONLYRETURN As Long = &H8000
Const OFN_NOVALIDATE As Long = &H100
Const OFN_OVERWRITEPROMPT As Long = &H2
Const OFN_PATHMUSTEXIST As Long = &H800
Const OFN_READONLY As Long = &H1
Const OFN_SHOWHELP As Long = &H10
 
Top