Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Listing files in a listbox

I would like to be able to open a folder and list all the subfolders in one
listbox. Then I would like to be able to select a folder from that listbox
and display all the files in another listbox
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,327
Default Listing files in a listbox

Hi

You are familiar with

Sub test()
Dim F As Variant
F = Application.GetOpenFilename
If Not F = False Then MsgBox CStr(F)
End Sub

?

What you request is possible, but how will you know where the starting
folder is and that it's always two levels above where the file is ?

HTH. Best wishes Harald

"dcstech" skrev i melding
...
I would like to be able to open a folder and list all the subfolders in

one
listbox. Then I would like to be able to select a folder from that

listbox
and display all the files in another listbox



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Listing files in a listbox

Harald,
What I am doing is this. I have a main folder on a server. In the main
folder I have about 25 sub folders. I want to be able to list all these
folders in a listbox. I want to do this in the code so that any time a new
folder is added it will automatically appear in the listbox.



"Harald Staff" wrote:

Hi

You are familiar with

Sub test()
Dim F As Variant
F = Application.GetOpenFilename
If Not F = False Then MsgBox CStr(F)
End Sub

?

What you request is possible, but how will you know where the starting
folder is and that it's always two levels above where the file is ?

HTH. Best wishes Harald

"dcstech" skrev i melding
...
I would like to be able to open a folder and list all the subfolders in

one
listbox. Then I would like to be able to select a folder from that

listbox
and display all the files in another listbox




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 117
Default Listing files in a listbox

Once the VB editor is open, go to 'Tools References' and set a reference
to "Microsoft Scripting Runtime"

I tested using a top folder of "C:\Test", you will need to change to the
path of the folder on your server. This does not deal with subfolders of
subfolders since it didn't sound like you would have that situation. I have
a UserForm1 with ListBox1 and ListBox2. When the form is activated,
ListBox1 is populated with a blank line and then the list of all subfolders
of C:\Test. When one of the subfolders is selected ListBox2 is cleared and
then populated with a single blank line followed by the list of files
contained in the selected subfolder.

Dim FSO As Scripting.FileSystemObject
Dim topFldr As Scripting.Folder
Dim someSub As Scripting.Folder
Dim workFldr As Scripting.Folder
Dim someFile As Scripting.File


Private Sub ListBox1_AfterUpdate()
Set workFldr = FSO.GetFolder("C:\Test\" & ListBox1.Value)
ListBox2.Clear
ListBox2.AddItem " "
For Each someFile In workFldr.Files
ListBox2.AddItem someFile.Name
Next someFile

End Sub


Private Sub UserForm_Activate()
Set FSO = New Scripting.FileSystemObject
Set topFldr = FSO.GetFolder("C:\Test")
ListBox1.AddItem " "
For Each someSub In topFldr.SubFolders
ListBox1.AddItem someSub.Name
Next someSub

End Sub

Private Sub UserForm_Deactivate()
Set FSO = Nothing
End Sub


Steve
"dcstech" wrote in message
...
I would like to be able to open a folder and list all the subfolders in one
listbox. Then I would like to be able to select a folder from that
listbox
and display all the files in another listbox



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 94
Default Listing files in a listbox

I built a program which would take a given directory, list all
sub-directories and files in them to a spread sheet, allow you to modify the
names, attributes, and/or directories for all files, and go back through the
list to re-name, move, and alter attributes to the files. Came out pretty
handy. I used a recurisve method to push new directories encountered onto a
stack and when the time came, pop them off and treat them like the
originally selected directory. (Recursion was controlled by the user, so it
didn't confuse the user too much. He could work with just one directory or
the whole shebang.)

But I'm not really that advanced in VBA. I just used simple file
manipulation techniques:
ChDrive to select the disk
ChrDir to select the directory
Name to change a files name and/or the directory in which it resides
SetAttr to change attributes
But most importantly, the Dir function to get files listed in a directory.

Could look something like this ...
fnm = Dir("d:\pathnameyouwanttofindfilesanddirectoriesin ", vbNormal)
do until fnm = "" 'No more files in that directory
Put 'er in the listbox using .Additem
if fnm is a directory, remember this for later processing
fnm = Dir 'Get the next file name in the directory
loop

If this isn't totally off the wall, I'd be happy to expound on this type of
program for you and give you more specific hints.

-Tim

"Steve Yandl" wrote in message
...
Once the VB editor is open, go to 'Tools References' and set a reference
to "Microsoft Scripting Runtime"

I tested using a top folder of "C:\Test", you will need to change to the
path of the folder on your server. This does not deal with subfolders of
subfolders since it didn't sound like you would have that situation. I

have
a UserForm1 with ListBox1 and ListBox2. When the form is activated,
ListBox1 is populated with a blank line and then the list of all

subfolders
of C:\Test. When one of the subfolders is selected ListBox2 is cleared

and
then populated with a single blank line followed by the list of files
contained in the selected subfolder.

Dim FSO As Scripting.FileSystemObject
Dim topFldr As Scripting.Folder
Dim someSub As Scripting.Folder
Dim workFldr As Scripting.Folder
Dim someFile As Scripting.File


Private Sub ListBox1_AfterUpdate()
Set workFldr = FSO.GetFolder("C:\Test\" & ListBox1.Value)
ListBox2.Clear
ListBox2.AddItem " "
For Each someFile In workFldr.Files
ListBox2.AddItem someFile.Name
Next someFile

End Sub


Private Sub UserForm_Activate()
Set FSO = New Scripting.FileSystemObject
Set topFldr = FSO.GetFolder("C:\Test")
ListBox1.AddItem " "
For Each someSub In topFldr.SubFolders
ListBox1.AddItem someSub.Name
Next someSub

End Sub

Private Sub UserForm_Deactivate()
Set FSO = Nothing
End Sub


Steve
"dcstech" wrote in message
...
I would like to be able to open a folder and list all the subfolders in

one
listbox. Then I would like to be able to select a folder from that
listbox
and display all the files in another listbox





Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
LIsting Files in Excel Sudhir Amin[_2_] Excel Discussion (Misc queries) 1 January 17th 08 02:56 PM
Listing Temporary Internet Files Alan Phang Excel Programming 3 February 11th 04 04:09 AM
Listing files within a folder Jeff Excel Programming 3 December 15th 03 12:28 PM
listing items from listbox Gerry[_5_] Excel Programming 2 October 18th 03 02:45 AM
Listing files in directories. skmr3 Excel Programming 0 July 11th 03 12:50 AM


All times are GMT +1. The time now is 03:15 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"