Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
JRP JRP is offline
external usenet poster
 
Posts: 3
Default File list - list filenames in excel

Hi, I have tryed this code listed below and it work, but as you see it only
list files in folder spesifyed in: .LookIn = ...

what I want to do is to find files from a dialogbox.

Any of you who can tell me how?????
--------------------------------------------------------------
Function CreateFileList(FileFilter As String, _
IncludeSubFolder As Boolean) As Variant
' returns the full filename for files matching
' the filter criteria in the current folder
Dim FileList() As String, FileCount As Long
CreateFileList = ""
Erase FileList
If FileFilter = "" Then FileFilter = "*.*" ' all files
With Application.FileSearch
.NewSearch
.LookIn = "C:\My Documents"
.Filename = FileFilter
.SearchSubFolders = IncludeSubFolder
.FileType = msoFileTypeAllFiles
If .Execute(SortBy:=msoSortByFileName, _
SortOrder:=msoSortOrderAscending) = 0 Then Exit Function
ReDim FileList(.FoundFiles.Count)
For FileCount = 1 To .FoundFiles.Count
FileList(FileCount) = .FoundFiles(FileCount)
Next FileCount
.FileType = msoFileTypeExcelWorkbooks ' reset filetypes
End With
CreateFileList = FileList
Erase FileList
End Function

Sub TestCreateFileList()
Dim FileNamesList As Variant, i As Integer
'ChDir "C:\Levende"
' activate the desired startfolder for the filesearch
FileNamesList = CreateFileList("*.*", False)
' performs the filesearch, includes any subfolders
' present the result
Range("A:A").ClearContents
For i = 1 To UBound(FileNamesList)
Cells(i + 4, 3).Formula = FileNamesList(i)
Next i
End Sub
-----------------------------------------------------------------------------
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 272
Default File list - list filenames in excel

Try Application.GetOpenFileName

--
Charles Chickering

"A good example is twice the value of good advice."


"JRP" wrote:

Hi, I have tryed this code listed below and it work, but as you see it only
list files in folder spesifyed in: .LookIn = ...

what I want to do is to find files from a dialogbox.

Any of you who can tell me how?????
--------------------------------------------------------------
Function CreateFileList(FileFilter As String, _
IncludeSubFolder As Boolean) As Variant
' returns the full filename for files matching
' the filter criteria in the current folder
Dim FileList() As String, FileCount As Long
CreateFileList = ""
Erase FileList
If FileFilter = "" Then FileFilter = "*.*" ' all files
With Application.FileSearch
.NewSearch
.LookIn = "C:\My Documents"
.Filename = FileFilter
.SearchSubFolders = IncludeSubFolder
.FileType = msoFileTypeAllFiles
If .Execute(SortBy:=msoSortByFileName, _
SortOrder:=msoSortOrderAscending) = 0 Then Exit Function
ReDim FileList(.FoundFiles.Count)
For FileCount = 1 To .FoundFiles.Count
FileList(FileCount) = .FoundFiles(FileCount)
Next FileCount
.FileType = msoFileTypeExcelWorkbooks ' reset filetypes
End With
CreateFileList = FileList
Erase FileList
End Function

Sub TestCreateFileList()
Dim FileNamesList As Variant, i As Integer
'ChDir "C:\Levende"
' activate the desired startfolder for the filesearch
FileNamesList = CreateFileList("*.*", False)
' performs the filesearch, includes any subfolders
' present the result
Range("A:A").ClearContents
For i = 1 To UBound(FileNamesList)
Cells(i + 4, 3).Formula = FileNamesList(i)
Next i
End Sub
-----------------------------------------------------------------------------

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default File list - list filenames in excel

Sub BBB()
Dim v As Variant
v = CreateFileList("Excel Files (*.xls),*.xls")
If Not IsEmpty(v) Then
For i = LBound(v) To UBound(v)
Debug.Print v(i)
Next
End If
End Sub

Function CreateFileList(FFilter As String _
) As Variant
Dim flist As Variant
If FFilter = "" Then FFilter = "All (*.*),*.*"
Debug.Print FFilter
flist = Application.GetOpenFilename( _
FileFilter:=FFilter, _
MultiSelect:=True)
If Not IsArray(flist) Then
CreateFileList = emtpy
Else
CreateFileList = flist
End If
End Function


--
Regards,
Tom Ogilvy



"JRP" wrote in message
...
Hi, I have tryed this code listed below and it work, but as you see it
only
list files in folder spesifyed in: .LookIn = ...

what I want to do is to find files from a dialogbox.

Any of you who can tell me how?????
--------------------------------------------------------------
Function CreateFileList(FileFilter As String, _
IncludeSubFolder As Boolean) As Variant
' returns the full filename for files matching
' the filter criteria in the current folder
Dim FileList() As String, FileCount As Long
CreateFileList = ""
Erase FileList
If FileFilter = "" Then FileFilter = "*.*" ' all files
With Application.FileSearch
.NewSearch
.LookIn = "C:\My Documents"
.Filename = FileFilter
.SearchSubFolders = IncludeSubFolder
.FileType = msoFileTypeAllFiles
If .Execute(SortBy:=msoSortByFileName, _
SortOrder:=msoSortOrderAscending) = 0 Then Exit Function
ReDim FileList(.FoundFiles.Count)
For FileCount = 1 To .FoundFiles.Count
FileList(FileCount) = .FoundFiles(FileCount)
Next FileCount
.FileType = msoFileTypeExcelWorkbooks ' reset filetypes
End With
CreateFileList = FileList
Erase FileList
End Function

Sub TestCreateFileList()
Dim FileNamesList As Variant, i As Integer
'ChDir "C:\Levende"
' activate the desired startfolder for the filesearch
FileNamesList = CreateFileList("*.*", False)
' performs the filesearch, includes any subfolders
' present the result
Range("A:A").ClearContents
For i = 1 To UBound(FileNamesList)
Cells(i + 4, 3).Formula = FileNamesList(i)
Next i
End Sub
-----------------------------------------------------------------------------


  #4   Report Post  
Posted to microsoft.public.excel.programming
JRP JRP is offline
external usenet poster
 
Posts: 3
Default File list - list filenames in excel

Hi,

Thank you for helping me.
I'm absolutly led in the right direction. But:

I got up the file selector box and was able to pic files(excel),
but they did not get listed up in the excel sheet.
Do I have to do something with the code U sendt?

I should have told u in the beginning, that I'm not a programmer, and need
full assistant. Maby I can manage it if U give me many hints.

Regards
Jim



"Tom Ogilvy" wrote:

Sub BBB()
Dim v As Variant
v = CreateFileList("Excel Files (*.xls),*.xls")
If Not IsEmpty(v) Then
For i = LBound(v) To UBound(v)
Debug.Print v(i)
Next
End If
End Sub

Function CreateFileList(FFilter As String _
) As Variant
Dim flist As Variant
If FFilter = "" Then FFilter = "All (*.*),*.*"
Debug.Print FFilter
flist = Application.GetOpenFilename( _
FileFilter:=FFilter, _
MultiSelect:=True)
If Not IsArray(flist) Then
CreateFileList = emtpy
Else
CreateFileList = flist
End If
End Function


--
Regards,
Tom Ogilvy



"JRP" wrote in message
...
Hi, I have tryed this code listed below and it work, but as you see it
only
list files in folder spesifyed in: .LookIn = ...

what I want to do is to find files from a dialogbox.

Any of you who can tell me how?????
--------------------------------------------------------------
Function CreateFileList(FileFilter As String, _
IncludeSubFolder As Boolean) As Variant
' returns the full filename for files matching
' the filter criteria in the current folder
Dim FileList() As String, FileCount As Long
CreateFileList = ""
Erase FileList
If FileFilter = "" Then FileFilter = "*.*" ' all files
With Application.FileSearch
.NewSearch
.LookIn = "C:\My Documents"
.Filename = FileFilter
.SearchSubFolders = IncludeSubFolder
.FileType = msoFileTypeAllFiles
If .Execute(SortBy:=msoSortByFileName, _
SortOrder:=msoSortOrderAscending) = 0 Then Exit Function
ReDim FileList(.FoundFiles.Count)
For FileCount = 1 To .FoundFiles.Count
FileList(FileCount) = .FoundFiles(FileCount)
Next FileCount
.FileType = msoFileTypeExcelWorkbooks ' reset filetypes
End With
CreateFileList = FileList
Erase FileList
End Function

Sub TestCreateFileList()
Dim FileNamesList As Variant, i As Integer
'ChDir "C:\Levende"
' activate the desired startfolder for the filesearch
FileNamesList = CreateFileList("*.*", False)
' performs the filesearch, includes any subfolders
' present the result
Range("A:A").ClearContents
For i = 1 To UBound(FileNamesList)
Cells(i + 4, 3).Formula = FileNamesList(i)
Next i
End Sub
-----------------------------------------------------------------------------



  #5   Report Post  
Posted to microsoft.public.excel.programming
JRP JRP is offline
external usenet poster
 
Posts: 3
Default File list - list filenames in excel

YESYESYESYESYESYESYESYESYESYESYESYESY

Finaly I manage to list filenames in excel by selecting them from folders.
Thank you Tom Ogilvy, you led me there.

I changed a bit on the code you suggested, and BAM, the files popt up
right where I wanted them.

Try IT:

Function CreateFileList(FFilter As String _
) As Variant
Dim flist As Variant
If FFilter = "" Then FFilter = "All (*.*),*.*"
Debug.Print FFilter
flist = Application.GetOpenFilename( _
FileFilter:=FFilter, _
MultiSelect:=True)
If Not IsArray(flist) Then
CreateFileList = emtpy
Else
CreateFileList = flist
End If
End Function


Sub BBB()
Dim v As Variant, i As Integer
v = CreateFileList("All Files (*.*),*.*")
Range("A:A").ClearContents
If Not IsEmpty(v) Then
For i = 1 To UBound(v)
Cells(i + 4, 3).Formula = v(i)
Next
End If
End Sub

BEST REGARDS
HAPPY MAN
Jim P



"JRP" wrote:

Hi,

Thank you for helping me.
I'm absolutly led in the right direction. But:

I got up the file selector box and was able to pic files(excel),
but they did not get listed up in the excel sheet.
Do I have to do something with the code U sendt?

I should have told u in the beginning, that I'm not a programmer, and need
full assistant. Maby I can manage it if U give me many hints.

Regards
Jim



"Tom Ogilvy" wrote:

Sub BBB()
Dim v As Variant
v = CreateFileList("Excel Files (*.xls),*.xls")
If Not IsEmpty(v) Then
For i = LBound(v) To UBound(v)
Debug.Print v(i)
Next
End If
End Sub

Function CreateFileList(FFilter As String _
) As Variant
Dim flist As Variant
If FFilter = "" Then FFilter = "All (*.*),*.*"
Debug.Print FFilter
flist = Application.GetOpenFilename( _
FileFilter:=FFilter, _
MultiSelect:=True)
If Not IsArray(flist) Then
CreateFileList = emtpy
Else
CreateFileList = flist
End If
End Function


--
Regards,
Tom Ogilvy



"JRP" wrote in message
...
Hi, I have tryed this code listed below and it work, but as you see it
only
list files in folder spesifyed in: .LookIn = ...

what I want to do is to find files from a dialogbox.

Any of you who can tell me how?????
--------------------------------------------------------------
Function CreateFileList(FileFilter As String, _
IncludeSubFolder As Boolean) As Variant
' returns the full filename for files matching
' the filter criteria in the current folder
Dim FileList() As String, FileCount As Long
CreateFileList = ""
Erase FileList
If FileFilter = "" Then FileFilter = "*.*" ' all files
With Application.FileSearch
.NewSearch
.LookIn = "C:\My Documents"
.Filename = FileFilter
.SearchSubFolders = IncludeSubFolder
.FileType = msoFileTypeAllFiles
If .Execute(SortBy:=msoSortByFileName, _
SortOrder:=msoSortOrderAscending) = 0 Then Exit Function
ReDim FileList(.FoundFiles.Count)
For FileCount = 1 To .FoundFiles.Count
FileList(FileCount) = .FoundFiles(FileCount)
Next FileCount
.FileType = msoFileTypeExcelWorkbooks ' reset filetypes
End With
CreateFileList = FileList
Erase FileList
End Function

Sub TestCreateFileList()
Dim FileNamesList As Variant, i As Integer
'ChDir "C:\Levende"
' activate the desired startfolder for the filesearch
FileNamesList = CreateFileList("*.*", False)
' performs the filesearch, includes any subfolders
' present the result
Range("A:A").ClearContents
For i = 1 To UBound(FileNamesList)
Cells(i + 4, 3).Formula = FileNamesList(i)
Next i
End Sub
-----------------------------------------------------------------------------



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
List Filenames from Folder Eskimo Excel Programming 1 May 19th 06 08:41 PM
List all filenames & tab names Deeds Excel Worksheet Functions 5 May 18th 06 11:16 PM
Getting a list of filenames Tom Ogilvy Excel Programming 3 April 13th 05 04:31 PM
Getting a list of filenames Bernie Deitrick Excel Programming 0 April 13th 05 02:55 PM
List out FileNames.xls with K4 Blank JMay Excel Programming 4 December 7th 03 04:35 PM


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