Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 91
Default Populate combobox with folder names

I had found this code to show folder names that displays in a msgbox,
is it possible to get the list of folder names into a combobox?

---------------------------------------

Sub ListFolders()
Dim fs, f, f1, fc, s
Dim folderspec
folderspec = "C:\Excel\"
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFolder(folderspec)
Set fc = f.SubFolders
For Each f1 In fc
s = s & f1.Name
s = s & vbCrLf

Next
MsgBox s


End Sub


----------------------------------------

This is for excel 2000

Thanks
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 411
Default Populate combobox with folder names

is the combobox on a worksheet or a userform?
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 91
Default Populate combobox with folder names

On Feb 18, 5:05*pm, dan dungan wrote:
is the combobox on a worksheet or a userform?


Thanks for the reply, it will be from the controlls toolbar that will
be on the worksheet.
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Populate combobox with folder names

Option Explicit
Sub ListFolders()
Dim fs, f, f1, fc, s
Dim folderspec
folderspec = "C:\Excel\"
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFolder(folderspec)
Set fc = f.SubFolders
For Each f1 In fc
Worksheets("Sheet1").ComboBox1.AddItem f1.Name
Next f1
End Sub

Change the name of the worksheet and the name of the combobox if you have to.

damorrison wrote:

On Feb 18, 5:05 pm, dan dungan wrote:
is the combobox on a worksheet or a userform?


Thanks for the reply, it will be from the controlls toolbar that will
be on the worksheet.


--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 91
Default Populate combobox with folder names

Thank you, that works great


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 91
Default Populate combobox with folder names

On Feb 18, 8:08*pm, damorrison wrote:
Thank you, that works great


The code works well.

When I use it on a system that uses two screens, and click the
ComboBox, the list shows up on the opposite screen as the combobox. I
then used a UserForm instead to populate the combobox, placing the
code in UserForm_Initialize, it populated just fine, but then again,
when I click the combobox in the UserForm, the list still shows up in
the opposite screen instead of the screen with the userform, is there
a way to stop this from happening?
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Populate combobox with folder names

I don't understand.

The code puts the list in a combobox on Sheet1. I don't see anything that uses
a userform.

damorrison wrote:

On Feb 18, 8:08 pm, damorrison wrote:
Thank you, that works great


The code works well.

When I use it on a system that uses two screens, and click the
ComboBox, the list shows up on the opposite screen as the combobox. I
then used a UserForm instead to populate the combobox, placing the
code in UserForm_Initialize, it populated just fine, but then again,
when I click the combobox in the UserForm, the list still shows up in
the opposite screen instead of the screen with the userform, is there
a way to stop this from happening?


--

Dave Peterson
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
Populate ComboBox with Worksheet Names Allen Excel Programming 4 November 17th 09 07:45 PM
How to List the names of the subfolders present in the folder (path of folder is given in the textbox by user ) divya Excel Programming 3 November 30th 06 11:34 AM
Populating ComboBox with Folder Names Tyrell Excel Programming 1 March 8th 06 04:25 PM
populate combobox with sheet names David Goodall Excel Programming 3 September 12th 04 12:37 PM
populate combobox with sheet names David Goodall Excel Programming 0 September 12th 04 08:55 AM


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

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"