Display a select folder dialog box in VB6

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", _

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!

Editor's Picks

Free Newsletters, In your Inbox