?
Solved

Open File CmdDialog

Posted on 2003-02-26
4
Medium Priority
?
305 Views
Last Modified: 2006-11-17
Hi all,
How to open the Open File Window for user to choose a specific FOLDER (not file) ?

coz the macro tat i am doing need user to specific a target folder to work on, and i am going to put a 'BROWSE' command button for that purpose
After user has select the target path, the path will be shown in a textbox as well.

Can anyone tell me how to do that? And what library to be included ?

0
Comment
Question by:KCChan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 13

Expert Comment

by:cri
ID: 8031996
0
 
LVL 11

Accepted Solution

by:
Steiner earned 400 total points
ID: 8032065
Put this into a module:

Option Explicit

Public 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 Long
End Type

Public Declare Sub CoTaskMemFree Lib "ole32.dll" (ByVal hMem As Long)
Public Declare Function lstrcat Lib "kernel32" Alias "lstrcatA" (ByVal lsString1 As String, ByVal lpString2 As String) As Long
Public Declare Function SHBrowseForFolder Lib "shell32" (lpbi As BrowseInfo) As Long
Public Declare Function SHGetPathFromIDList Lib "shell32" (ByVal pidList As Long, ByVal lpBuffer As String) As Long

Public Const BIF_RETURNONLYFSDIRS = 1
Public Const MAX_PATH = 256

Public Function BrowseForFolder(Beschriftung As String)
Dim pidl&, path$, bi As BrowseInfo
   With bi
      .hwndOwner = Screen.ActiveForm.hWnd
      .lpszTitle = lstrcat(Beschriftung, " ")
      .ulFlags = BIF_RETURNONLYFSDIRS
   End With
   pidl = SHBrowseForFolder(bi)
   If pidl Then
      path = String(MAX_PATH, 0)
      SHGetPathFromIDList pidl, path
      CoTaskMemFree pidl
      path = Left$(path, InStr(path, vbNullChar) - 1)
   End If
   BrowseForFolder = path
End Function

In your form you just have to add a button with the following code:

Private Sub Command1_Click()
   Text1.Text = BrowseForFolder("Choose a directory:")
End Sub

Greets
Steiner
0
 

Author Comment

by:KCChan
ID: 8054690
Thanks a lot, this is what exactly i was looking for.

0
 
LVL 13

Expert Comment

by:cri
ID: 8055265
And you got it twice....

0

Featured Post

Office 365 Training for Admins - 7 Day Trial

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
If you need to forecast numbers -- typically for finance -- the Windows and Mac versions of Excel 2016 have a basket of tools to get the job done.
The viewer will learn how to  create a slide that will launch other presentations in Microsoft PowerPoint. In the finished slide, each item launches a new PowerPoint presentation and when each is finished it automatically comes back to this slide: …
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question