View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
[email protected] mike.r.harris@blueyonder.co.uk is offline
external usenet poster
 
Posts: 11
Default Better way to fill a ComboBox ?


Jim Cone wrote:
Just noticed that...
For Loopy = 1 to 7
--should be--
For Loopy = 0 to 6
--
Jim Cone


"Jim Cone"
wrote in message
Not sure whether "Dir" will work as shown, as it was too much
bother to do the setup to test it.
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware


Private Sub ComboBox1_DropButtonClick()
Dim myPath As String
Dim i As Long
Dim DayO As String
Dim Loopy As Integer
Dim varDays As Variant
Application.ScreenUpdating = False

'HomeBook = ThisWorkbook.Name
myPath = _
ThisWorkbook.Sheets("Configuration").Range("Report ExportPath").Value
ThisWorkbook.Sheets("Report").ComboBox1.Clear
ThisWorkbook.Sheets("Report").ComboBox1.Text = _
"Select a previous shift to View"
varDays = Array("Monday*.xls", "Tuesday*.xls", "Wednesday*.xls", _
"Thursday*.xls", "Friday*.xls", "Saturday*.xls", "Sunday*.xls")
For Loopy = 1 To 7
DayO = varDays(Loopy)
With Application.FileSearch
.NewSearch
.LookIn = myPath
.SearchSubFolders = False
.Filename = DayO
.FileType = msoFileTypeExcelWorkbooks
If .Execute() 0 Then
For i = 1 To .FoundFiles.Count
ThisWorkbook.Sheets("Report").ComboBox1.AddItem Dir(.FoundFiles(i))
Next i
End If
End With
Next
Application.ScreenUpdating = True
End Sub
'-----------------


Jim, thanks for taking the time to reply...... I have taken your code
and adapted it as follows...

'
Private Sub ComboBox1_DropButtonClick()
Dim myPath As String
Dim i As Long
Dim DayO As String
Dim Loopy As Integer
Dim varDays As Variant
Application.ScreenUpdating = False

myPath =
ThisWorkbook.Sheets("Configuration").Range("Report ExportPath").Value
ThisWorkbook.Sheets("Report").ComboBox1.Clear
ThisWorkbook.Sheets("Report").ComboBox1.Text = _
"Select a previous shift to View"
varDays = Array("Monday*.xls", "Tuesday*.xls", "Wednesday*.xls", _
"Thursday*.xls", "Friday*.xls", "Saturday*.xls", "Sunday*.xls")
For Loopy = 0 To 6
DayO = varDays(Loopy)
With Application.FileSearch
.NewSearch
.LookIn = myPath
.SearchSubFolders = False
.Filename = DayO
.FileType = msoFileTypeExcelWorkbooks
If .Execute() 0 Then
For i = 1 To .FoundFiles.Count
ThisWorkbook.Sheets("Report").ComboBox1.AddItem
Left(Dir(.FoundFiles(i)), (Len(Dir(.FoundFiles(i))) - 4))
Next i
End If
End With
Next
Application.ScreenUpdating = True
End Sub

The only chage was to remove the ".xls" The file naming disipline of
"day-date-shift" looks just that bit better without the file extension
showing. And yes, Dir does work. Oh and I changed the array base ... 0
to 6

Again, many thanks for improving the code...... Mike