ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Filename and creation timestamp in 2-column combobox (https://www.excelbanter.com/excel-programming/290584-filename-creation-timestamp-2-column-combobox.html)

L Mehl

Filename and creation timestamp in 2-column combobox
 
Hello --

An application creates one or more text files, including a specific text
string in the name.

I want to display all file names and creation timestamp in a 2-column
combobox so the user can select the one which is to be imported into a
worksheet.

Can anyone suggest ways to do this, or tell me of examples they know of
which already do it?

Thanks for any help.

Larry Mehl





---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.576 / Virus Database: 365 - Release Date: 1/31/2004



Bob Phillips[_6_]

Filename and creation timestamp in 2-column combobox
 
Larry,

Here's some code to load a combobox

Private Sub UserForm_Initialize()
Dim oFSO As Object
Dim oFolder As Object
Dim oFile As Object

Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oFolder = oFSO.Getfolder("c:\myTest")

With Me.ComboBox1
.ColumnCount = 2
For Each oFile In oFolder.Files
If oFile.Type = "Text Document" Then
.AddItem oFile.Name
.List(.ListCount - 1, 1) = oFile.DateLastModified
End If
Next oFile
.ListIndex = 0
End With

End Sub


--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"L Mehl" wrote in message
...
Hello --

An application creates one or more text files, including a specific text
string in the name.

I want to display all file names and creation timestamp in a 2-column
combobox so the user can select the one which is to be imported into a
worksheet.

Can anyone suggest ways to do this, or tell me of examples they know of
which already do it?

Thanks for any help.

Larry Mehl





---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.576 / Virus Database: 365 - Release Date: 1/31/2004





Shailesh Shah[_2_]

Filename and creation timestamp in 2-column combobox
 
Hi,

Another method to try,

Example from VBA Help & modified.

Private Sub UserForm_Initialize()
Dim mypath, myname

mypath = "c:\windows\" ' Set the path.
myname = Dir(mypath, vbDirectory) ' Retrieve the first entry.
With Me.ComboBox1
Do While myname < "" ' Start the loop.
' Ignore the current directory and the encompassing
directory.
If myname < "." And myname < ".." Then
' Use bitwise comparison to make sure MyName is a Fileanme

If (GetAttr(mypath & myname) And vbDirectory) <
vbDirectory Then

'Debug.Print MyName ' Display entry only if it
represents a filename
If UCase(Right(myname, 4)) = ".TXT" Then
.ColumnCount = 2
.AddItem myname
.List(.ListCount - 1, 1) = FileDateTime(mypath &
myname)
End If
End If
End If
myname = Dir ' Get next entry.
Loop
If .ListCount 0 Then .ListIndex = 0
End With
End Sub



Regards,
Shah Shailesh
http://members.lycos.co.uk/shahweb/


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

L Mehl

Filename and creation timestamp in 2-column combobox
 
Bob --

Thank you for the method.

It works like a charm. I revised it to add a 3rd column (a value calculated
by the code) to the combobox and it still worked!

Another question:

Is there a property of a combo box which displays vertical lines between the
columns?

Larry




"Bob Phillips" wrote in message
...
Larry,

Here's some code to load a combobox

Private Sub UserForm_Initialize()
Dim oFSO As Object
Dim oFolder As Object
Dim oFile As Object

Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oFolder = oFSO.Getfolder("c:\myTest")

With Me.ComboBox1
.ColumnCount = 2
For Each oFile In oFolder.Files
If oFile.Type = "Text Document" Then
.AddItem oFile.Name
.List(.ListCount - 1, 1) = oFile.DateLastModified
End If
Next oFile
.ListIndex = 0
End With

End Sub


--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"L Mehl" wrote in message
...
Hello --

An application creates one or more text files, including a specific text
string in the name.

I want to display all file names and creation timestamp in a 2-column
combobox so the user can select the one which is to be imported into a
worksheet.

Can anyone suggest ways to do this, or tell me of examples they know of
which already do it?

Thanks for any help.

Larry Mehl





---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.576 / Virus Database: 365 - Release Date: 1/31/2004






---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.576 / Virus Database: 365 - Release Date: 1/30/2004



L Mehl

Filename and creation timestamp in 2-column combobox
 
Thank you, Shah.

Larry

"Shailesh Shah" wrote in message
...
Hi,

Another method to try,

Example from VBA Help & modified.

Private Sub UserForm_Initialize()
Dim mypath, myname

mypath = "c:\windows\" ' Set the path.
myname = Dir(mypath, vbDirectory) ' Retrieve the first entry.
With Me.ComboBox1
Do While myname < "" ' Start the loop.
' Ignore the current directory and the encompassing
directory.
If myname < "." And myname < ".." Then
' Use bitwise comparison to make sure MyName is a Fileanme

If (GetAttr(mypath & myname) And vbDirectory) <
vbDirectory Then

'Debug.Print MyName ' Display entry only if it
represents a filename
If UCase(Right(myname, 4)) = ".TXT" Then
.ColumnCount = 2
.AddItem myname
.List(.ListCount - 1, 1) = FileDateTime(mypath &
myname)
End If
End If
End If
myname = Dir ' Get next entry.
Loop
If .ListCount 0 Then .ListIndex = 0
End With
End Sub



Regards,
Shah Shailesh
http://members.lycos.co.uk/shahweb/


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!



---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.576 / Virus Database: 365 - Release Date: 1/30/2004




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

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com