Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Populate Listbox with File Name Only

Hi,
I have various ways to populate a list box with .xls files, yet when I
do this I get the FileName to appear as well as the entire Directory
attached to that file. How should I go about Populating the list Box
with Only the File Name?
Right now in listbox1 I have

"C:\Program Files\File1.xls"
"C:\Program Files\File2.xls"
"C:\Program Files\File3.xls"

what I really want is

"File1.xls"
"File2.xls"
"File3.xls"

Thanks in advance!

Justin
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Populate Listbox with File Name Only

Where does the data come from?

--

HTH

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

"Justin" wrote in message
om...
Hi,
I have various ways to populate a list box with .xls files, yet when I
do this I get the FileName to appear as well as the entire Directory
attached to that file. How should I go about Populating the list Box
with Only the File Name?
Right now in listbox1 I have

"C:\Program Files\File1.xls"
"C:\Program Files\File2.xls"
"C:\Program Files\File3.xls"

what I really want is

"File1.xls"
"File2.xls"
"File3.xls"

Thanks in advance!

Justin



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Populate Listbox with File Name Only

Justin,

Try something like the following:

Dim FullName As String
Dim FName As String
Dim Pos As Integer
FullName = "C:\Temp\Book.xls"
Pos = InStrRev(FullName, "\")
FName = Mid(FullName, Pos + 1)


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com



"Justin" wrote in message
om...
Hi,
I have various ways to populate a list box with .xls files, yet

when I
do this I get the FileName to appear as well as the entire

Directory
attached to that file. How should I go about Populating the

list Box
with Only the File Name?
Right now in listbox1 I have

"C:\Program Files\File1.xls"
"C:\Program Files\File2.xls"
"C:\Program Files\File3.xls"

what I really want is

"File1.xls"
"File2.xls"
"File3.xls"

Thanks in advance!

Justin



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default Populate Listbox with File Name Only


"Justin" wrote in message
om...
Hi,
I have various ways to populate a list box with .xls files, yet when I
do this I get the FileName to appear as well as the entire Directory
attached to that file. How should I go about Populating the list Box
with Only the File Name?
Right now in listbox1 I have

"C:\Program Files\File1.xls"
"C:\Program Files\File2.xls"
"C:\Program Files\File3.xls"

what I really want is

"File1.xls"
"File2.xls"
"File3.xls"

Thanks in advance!

Justin


Not tested.

Sub TestMe()

Dim wb as Workbook

For Each wb in Workbooks
MyForm.ListBox1.AddItem wb.Name
Next wb

End Sub

-gk-


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Populate Listbox with File Name Only

Thanks for the replies. The Subs Worked great, yet I couldn't feed them
into my code. Thanks for the help



Sub SummarySheetSearchListBox()

' Dimension variables.
Dim myarray()
Dim FS As Object
Dim i As Integer
Dim NextFile As String

' Declare filesearch object.
Set FS = Application.FileSearch

' Set folder to search.
FS.LookIn = "C:\Summary Sheets\"

' Set file name to search for.
FS.Filename = ("*.xls")


' Execute the file search, and check to see if the file(s) are present.
If FS.Execute 0 Then

' Redimension the array to the number of files found.
ReDim myarray(FS.FoundFiles.Count)

' Loop through all found file names and fill the array.
For i = 1 To FS.FoundFiles.Count
myarray(i) = FS.FoundFiles(i)
Next i
Else
' Display message if no files were found.
MsgBox "No files were found"
End If

' Loop through the array and fill the list box on the UserForm.
For i = 1 To FS.FoundFiles.Count
SummarySheet.ListBox1.AddItem myarray(i)
Next i

' Display the UserForm.
SummarySheet.Show

End Sub

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


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Populate Listbox with File Name Only



I forgot to mention, this is the code that outputs
in Listbox1

c:\summary sheet\file1.xls
c:\summary sheet\file2.xls
c:\summary sheet\file3.xls

Thanks in advance

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
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 ldropdown listbox from a dbf. file niteman27 Excel Discussion (Misc queries) 0 December 1st 08 10:57 PM
Using Hidden Sheets to populate listbox MrPebody70 Excel Programming 1 August 21st 04 10:33 PM
populate listbox JSnader Excel Programming 2 December 6th 03 02:43 PM
Populate listBox Hamster Excel Programming 1 September 17th 03 01:14 PM
ListBox Populate Rod Taylor Excel Programming 3 July 22nd 03 12:11 AM


All times are GMT +1. The time now is 09:18 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"