Manoj
Manoj

Reputation: 5097

File Path Control

How to put a File path control in VBA front panel? I want the user to be able to select the browse button and select the file path rather than putting up dialog boxes all over the place. I need the user to select three or more file paths.

Upvotes: 4

Views: 8082

Answers (5)

nghmuon
nghmuon

Reputation: 11

Is this what you want?

FilePath = Application.GetOpenFilename

Upvotes: 1

jpinto3912
jpinto3912

Reputation: 1465

After re-re-reading your Q, it seams you want to steer away from dialog boxes!Oh well, I was going to say

I could post the hack about using MSDIAG on VBA, that explains how you can patch your registry to enable its use under VBA, without having other MS-VB products installed... but I rather have you google that one... you can certainly understand why.

But you don't want Dialog Boxes... you want controls and buttons: Use listboxes! To populate your listbox, use the Dir command (using method additem of the listbox). Two phases for achieving that:

  • first get the Directories (and prefix a "->" or whatever prior to adding it on the listbox, so that the user understands this is not a file);
  • then get filenames (you can filter by extension with the arguments of Dir, just as you would in DOS).

Finally, under OnClick and OnDoubleClick of the listbox, you must interpret the listbox default property (Item), check for "->" and use ChDir to change directory and repopulate, or you'll have your file selected.

The write up is sooooooo much more complicated than the code... trust me.

Upvotes: 3

Fionnuala
Fionnuala

Reputation: 91376

Perhaps the browse for folder API from the Microsoft MVPs site would suit:

http://www.mvps.org/access/api/api0002.htm

It uses SHBrowseForFolder mentioned by fwzgekg, and does not return a file dialog, it returns a browsable list of folders.

Upvotes: 1

Philippe Grondier
Philippe Grondier

Reputation: 11148

There is not direct VBA function for that. You can decide to combine a form (Access form, or a generic microsoft form) with 2 controls: (1) text box (2) browse button (which will finally use the fileDialog command or a windows API).

Upvotes: 1

fwzgekg
fwzgekg

Reputation: 321

Do you mean VBA for Microsoft Office or just general VBA?

In Office, Application.FileDialog(msoFileDialogOpen).

Otherwise, look at the Win32 API function SHBrowseForFolder (in shell32.dll). You can import it for use into VBA using the Declare Function keywords.

Upvotes: 2

Related Questions