On The Insider: Amanda Bynes in Crash

Display a select folder dialog box in VB6

Tags: Microsoft development tools, Peter Aitken, Microsoft Visual Basic 6.0, Visual Basic Tips Newsletter

  • Save
  • Print
  • Digg This
  • 2

Takeaway: VB6's Microsoft Shell and Automation Component allows you to select a folder. Follow Peter Aitken's instructions in this tip to learn how to show a particular folder's dialog box.

VB6's Common Dialog control makes it easy to let the user select a file, but what about selecting a folder? This is also easy to do with the Microsoft Shell and Automation component.

First, add a reference to this component, which is located in Shell32.dll, to your project. You'll also need declarations in your code. View Listing A to see the declarations.


Then create an instance of the Shell class:

Set shlShell = New Shell32.Shell

Finally, display the dialog box and return the result:

Set shlFolder = shlShell.BrowseForFolder(Me.hWnd, "Select a Folder", _
    BIF_RETURNONLYFSDIRS)

Now the selected folder is available in the property shlFolder.Title.

Miss a tip?

Check out the Visual Basic archive, and catch up on the most recent editions of Peter Aitken's column.

Advance your scripting skills to the next level with TechRepublic's free Visual Basic newsletter, delivered each Friday. Automatically sign up today!

  • Save
  • Print
  • Digg This
  • 2

Print/View all Posts Comments on this article

Using BrowserForFolder tipsimon.conway-smith@...  | 12/16/05
Lacks detail-very sketchyphilip29@...  | 12/16/05
So how do you add the reference?thomas.bihn@...  | 12/16/05
OK here's how to make this workChuckSomerville  | 12/16/05
previously confuseddon-supportguy  | 12/16/05
Handle the Cancel buttondoug.pocius@...  | 12/16/05
RE: Handle the Cancl buttona_espadas  | 07/30/08
Setting initial folderettiennes@...  | 02/09/06
Setting Root Foldermartius.mesquita@...  | 04/19/06
How can I make "My Computer" has rootmnarewec@...  | 09/21/07
Selecting the desktop.Amahdy  | 09/02/07
RE: Display a select folder dialog box in VB6adnanafridi86@...  | 01/04/08

What do you think?

Article Categories

Security
Security Solutions, IT Locksmith
Networking and Communications
E-mail Administration NetNote, Cisco Routers and Switches
CIO and IT Management
Project Management, CIO Issues, Strategies that Scale
Desktops, Laptops & OS
Windows 2000 Professional, Microsoft Word, Microsoft Excel, Microsoft Access, Windows XP,
Data Management
Oracle, SQL Server
Servers
Windows NT, Linux NetNote, Windows Server 2003
Career Development
Geek Trivia
Software/Web Development
Web Development Zone, Visual Basic, .NET
advertisement
Click Here