×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

VBA Code for File Browse

VBA Code for File Browse

VBA Code for File Browse

(OP)
I am trying to find the vba code which will do the following:

1) bring up a file menu to browse for a folder
2) allow the user to use the mouse to choose a directory path
3) read this path into vba to establish a path for all file operations.

Does anyone know the vba code to do this?

Thanks

RE: VBA Code for File Browse

Have you looked at FAQ559-1164?

RE: VBA Code for File Browse

This is a common workaround for a common problem.  The problem is not a SW problem.  It is an issue with Microsoft licensing.

Microsoft's license for VBA does not include access to certain objects, including the "Common Dialog" object used for opening and saving files, selecting colors, and printing.  The workaround uses access to Windows API to get what you need (all perfectly legal).

I use this in my "Copy Custom Info" macro, as well.  <http://www.esoxrepublic.com/freeware/>

I could be the world's greatest underachiever, if I could just learn to apply myself.
http://www.EsoxRepublic.com-SolidWorks API VB programming help

RE: VBA Code for File Browse

handleman,

Do you know a way I could get the BrowseForFolder to reside in a Userform, just like a Listbox or something? Currently I have to click a Browse button to pop the BrowseForFolder Open, and then once it Closes...all I see is the selected path and my Browse button. I'd much rather just leave the BrowseForFolder open and available to the User.

Thanks,
Ken

RE: VBA Code for File Browse

I don't think you can leave it open.  I'm not too familiar with the Common Dialog stuff myself, but I did remember it as being the first FAQ in the list.  

If you want that kind of functionality in a user form that stays open you may have to create your own using standard file/folder access calls in VBA.  If that's really something you want to do, here's a link to some sample code that'll get you well on your way.

http://www.blueclaw-db.com/listbox-directory.htm

Enjoy!

RE: VBA Code for File Browse

(OP)
Handleman

The link you provided solved my problem

Thanks

RE: VBA Code for File Browse

Handleman,

Thanks for the link. I am actually looking for a TreeView style interface that is avilable with full-blown VB-6. I was just hoping to keep the current project a SolidWorks macro, but VB-6 looks like my only alternative.

Thanks,
Ken

RE: VBA Code for File Browse

Are you sure you don't have the treeview control?  I am able to get this control in a SWX form.  Under "Tools - References", try enabling the Microsoft Windows Common Controls 6.  The actual file name is MSCOMCTL.OCX.  The treeview control (Microsoft Treeview Control 6) can then be added by right-clicking on the toolbox and selecting "Additional Controls".   

RE: VBA Code for File Browse

Ken,

Why not display the selected path in a label?  Then put a command button with "..." after the label.  Clicking the command button launches the browse window and allows you to update the label text.  Your code then takes the file path from the label caption.

RE: VBA Code for File Browse

Stoker,

Quote:

The treeview control (Microsoft Treeview Control 6) can then be added by right-clicking on the toolbox and selecting "Additional Controls".
Thanks! That is awesome, I have been looking for that for weeks.

Quote:

Why not display the selected path in a label?  Then put a command button with "..." after the label.
That is what I'm currently doing, but I get complaints about having to hit the extra button all the time just to select the next higher or lower directory.

Ken

RE: VBA Code for File Browse

Lots of good stuff here.  You will find folder browser somewhere here.
<http://allapi.net/>

I could be the world's greatest underachiever, if I could just learn to apply myself.
http://www.EsoxRepublic.com-SolidWorks API VB programming help

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources