Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations SSS148 on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBA Code for File Browse

Status
Not open for further replies.

Spurs

Mechanical
Nov 7, 2002
297
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
 
Replies continue below

Recommended for you

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. <
[bat]I could be the world's greatest underachiever, if I could just learn to apply myself.[bat]
-SolidWorks API VB programming help
 
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
 
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.


Enjoy!
 
Handleman

The link you provided solved my problem

Thanks
 
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
 
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".
 
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.
 
Stoker,

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.

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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor