Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 88
Default Folder Contents listed in Combo box

Hi all,
As mentioned in the Subject line, How would I list the contents of
a Folder eg. D:\Any\Contacts\?????. and have this info displayed in a Combo
Box within a worksheet, wherby the User is then able to pick a file to be
loaded in Excel, ensuring of course that only .xl folders are displayed. If
the folder has no content or does not exist, then to load a file by the name
of Contacts1.xls

Regards

Lee

  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 88
Default Folder Contents listed in Combo box

Sorry make that a list box not a combo box

"leerem" wrote:

Hi all,
As mentioned in the Subject line, How would I list the contents of
a Folder eg. D:\Any\Contacts\?????. and have this info displayed in a Combo
Box within a worksheet, wherby the User is then able to pick a file to be
loaded in Excel, ensuring of course that only .xl folders are displayed. If
the folder has no content or does not exist, then to load a file by the name
of Contacts1.xls

Regards

Lee

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11,501
Default Folder Contents listed in Combo box

Hi,

You didn't say where you list box was. This assumes iot's on a worksheet and
the code will execute when the workshet is activated. Change the directory to
suit

Private Sub Worksheet_Activate()
ListBox1.Clear
MyPath = "C:\"
MyName = Dir$(MyPath & "*.xls") 'only looks for xl files
With ListBox1
Do While MyName < ""
MyName = Left(MyName, Len(MyName) - 4) 'removes .XLS from end of name
.AddItem MyName
MyName = Dir
Loop
End With
End Sub

Mike

"leerem" wrote:

Sorry make that a list box not a combo box

"leerem" wrote:

Hi all,
As mentioned in the Subject line, How would I list the contents of
a Folder eg. D:\Any\Contacts\?????. and have this info displayed in a Combo
Box within a worksheet, wherby the User is then able to pick a file to be
loaded in Excel, ensuring of course that only .xl folders are displayed. If
the folder has no content or does not exist, then to load a file by the name
of Contacts1.xls

Regards

Lee

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 88
Default Folder Contents listed in Combo box

Hi Mike,

So assuming the list box was to be placed in Cell D12, Could I place this
code in

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

as I already have code in this procedure could I add it at the base so the
list box would only appear it the user selected it






"Mike H" wrote:

Hi,

You didn't say where you list box was. This assumes iot's on a worksheet and
the code will execute when the workshet is activated. Change the directory to
suit

Private Sub Worksheet_Activate()
ListBox1.Clear
MyPath = "C:\"
MyName = Dir$(MyPath & "*.xls") 'only looks for xl files
With ListBox1
Do While MyName < ""
MyName = Left(MyName, Len(MyName) - 4) 'removes .XLS from end of name
.AddItem MyName
MyName = Dir
Loop
End With
End Sub

Mike

"leerem" wrote:

Sorry make that a list box not a combo box

"leerem" wrote:

Hi all,
As mentioned in the Subject line, How would I list the contents of
a Folder eg. D:\Any\Contacts\?????. and have this info displayed in a Combo
Box within a worksheet, wherby the User is then able to pick a file to be
loaded in Excel, ensuring of course that only .xl folders are displayed. If
the folder has no content or does not exist, then to load a file by the name
of Contacts1.xls

Regards

Lee

  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11,501
Default Folder Contents listed in Combo box

Hi,

You can choose any event you want to call the code. If you used
selection_change you could limit it to when the actual selection was d12

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Address < ("$D$12") Then Exit Sub
ListBox1.Clear
MyPath = "C:\"
MyName = Dir$(MyPath & "*.xls") 'only looks for xl files
With ListBox1
Do While MyName < ""
MyName = Left(MyName, Len(MyName) - 4) 'removes .XLS from end of name
.AddItem MyName
MyName = Dir
Loop
End With

End Sub

Mike

"leerem" wrote:

Hi Mike,

So assuming the list box was to be placed in Cell D12, Could I place this
code in

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

as I already have code in this procedure could I add it at the base so the
list box would only appear it the user selected it






"Mike H" wrote:

Hi,

You didn't say where you list box was. This assumes iot's on a worksheet and
the code will execute when the workshet is activated. Change the directory to
suit

Private Sub Worksheet_Activate()
ListBox1.Clear
MyPath = "C:\"
MyName = Dir$(MyPath & "*.xls") 'only looks for xl files
With ListBox1
Do While MyName < ""
MyName = Left(MyName, Len(MyName) - 4) 'removes .XLS from end of name
.AddItem MyName
MyName = Dir
Loop
End With
End Sub

Mike

"leerem" wrote:

Sorry make that a list box not a combo box

"leerem" wrote:

Hi all,
As mentioned in the Subject line, How would I list the contents of
a Folder eg. D:\Any\Contacts\?????. and have this info displayed in a Combo
Box within a worksheet, wherby the User is then able to pick a file to be
loaded in Excel, ensuring of course that only .xl folders are displayed. If
the folder has no content or does not exist, then to load a file by the name
of Contacts1.xls

Regards

Lee

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
Folder Contents to Excel TC Daniel Excel Discussion (Misc queries) 2 January 23rd 08 05:53 PM
Listing Folder Contents into a Column LyndieBee Excel Worksheet Functions 1 August 29th 07 03:16 PM
Listing the contents of a folder [email protected] Excel Discussion (Misc queries) 2 April 12th 07 03:54 AM
add a folder to c:\ drive from cell A1 contents... [email protected] Excel Discussion (Misc queries) 1 July 25th 06 09:48 PM
How to exctract files listed in an Excel-file from a folder? skiern Excel Discussion (Misc queries) 2 May 6th 06 04:41 PM


All times are GMT +1. The time now is 01:01 PM.

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

About Us

"It's about Microsoft Excel"