VBA

VBA Function to Browse & Select from Directory

I have been building many applications using VBA to help users in automating processes. Somethings simply can’t be automated due to variability of some attribute. In my case determining the directory to use required input from the user. So I devised a simple function that will ask the user where the files are saved in a directory. The other code not mentioned in this post would extract the data from each file within the directory. First the application needed to know the correct file path to the directory to use.

I found the original code somewhere, but I never saved the source. Apologies for not attributing the original source. However, I know I made some modifications to suit my needs.

The function takes the input of a file path. This is if you know the general directory, but not the sub directory. The user can then select an ultimate directory within overall directory where the data being used is typically saved. Otherwise, the user would have to search through several directories to get to where it needs to go.

A valid file path is returned by the function, which then can be used within a sub or another function to know where to look for data.

Here is the code:

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Popular Posts


To Top