Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default update file list code for excel 2007

I just switch from Windows XP to Windows 2007 and I'm no longer able to run
this macro.
Can you help me...
Thanks
-----------------------------------------------

Sub ListFiles_01()
'Using FileSearch to list the files in a directory
Dim i As Integer
i = 1
With Application.FileSearch 'This is the problem'
..NewSearch
..LookIn = "C:\"
..Filename = "*.*"
.SearchSubFolders = True
'.SearchFolders = True
..Execute
For i = 1 To .FoundFiles.Count
Range("B" & i + 1).Value = .FoundFiles(i)
Range("C" & i + 1).Value = FileDateTime(.FoundFiles(i))
Range("D" & i + 1).Value = FileLen(.FoundFiles(i))
'Range("E" & i + 1).Value = Filename(.FoundFiles(i))
Next


End With


End Sub


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default update file list code for excel 2007

Hi

FileSearch is removed from Office 2007 because there where to many problems.

You can use FSO, you can steal a part of the code here to make your loop
http://www.rondebruin.nl/fso.htm



--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"answer33" wrote in message ...
I just switch from Windows XP to Windows 2007 and I'm no longer able to run
this macro.
Can you help me...
Thanks
-----------------------------------------------

Sub ListFiles_01()
'Using FileSearch to list the files in a directory
Dim i As Integer
i = 1
With Application.FileSearch 'This is the problem'
.NewSearch
.LookIn = "C:\"
.Filename = "*.*"
.SearchSubFolders = True
'.SearchFolders = True
.Execute
For i = 1 To .FoundFiles.Count
Range("B" & i + 1).Value = .FoundFiles(i)
Range("C" & i + 1).Value = FileDateTime(.FoundFiles(i))
Range("D" & i + 1).Value = FileLen(.FoundFiles(i))
'Range("E" & i + 1).Value = Filename(.FoundFiles(i))
Next


End With


End Sub


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default update file list code for excel 2007

Thanks's Ron, but can you be more specific.
I'm not sure what I'm suppose to paste and where to paste it.


"Ron de Bruin" wrote:

Hi

FileSearch is removed from Office 2007 because there where to many problems.

You can use FSO, you can steal a part of the code here to make your loop
http://www.rondebruin.nl/fso.htm



--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"answer33" wrote in message ...
I just switch from Windows XP to Windows 2007 and I'm no longer able to run
this macro.
Can you help me...
Thanks
-----------------------------------------------

Sub ListFiles_01()
'Using FileSearch to list the files in a directory
Dim i As Integer
i = 1
With Application.FileSearch 'This is the problem'
.NewSearch
.LookIn = "C:\"
.Filename = "*.*"
.SearchSubFolders = True
'.SearchFolders = True
.Execute
For i = 1 To .FoundFiles.Count
Range("B" & i + 1).Value = .FoundFiles(i)
Range("C" & i + 1).Value = FileDateTime(.FoundFiles(i))
Range("D" & i + 1).Value = FileLen(.FoundFiles(i))
'Range("E" & i + 1).Value = Filename(.FoundFiles(i))
Next


End With


End Sub



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default update file list code for excel 2007

You can try something like this

Change MyPath and Subfolders

Sub testme()
Get_File_Names_Test _
MyPath:="C:\Users\Ron\test", _
Subfolders:=False, _
ExtStr:="*.xl*"
End Sub

Sub Get_File_Names_Test(MyPath As String, Subfolders As Boolean, ExtStr As String)
Dim Fso_Obj As Object, RootFolder As Object
Dim SubFolderInRoot As Object, file As Object

Worksheets.Add

'Add a slash at the end if the user forget it
If Right(MyPath, 1) < "\" Then
MyPath = MyPath & "\"
End If

'Create FileSystemObject object
Set Fso_Obj = CreateObject("Scripting.FileSystemObject")

fnum = 0

'Test if the folder exist and set RootFolder
If Fso_Obj.FolderExists(MyPath) = False Then
MsgBox MyPath & " doesn't exist"
Exit Sub
End If
Set RootFolder = Fso_Obj.GetFolder(MyPath)


'Fill the array(myFiles)with the list of Excel files in the folder(s)
'Loop through the files in the RootFolder
For Each file In RootFolder.Files
If LCase(file.Name) Like LCase(ExtStr) Then
fnum = fnum + 1
Cells(fnum, 1) = MyPath & file.Name
Cells(fnum, 2) = FileDateTime(MyPath & file.Name)
Cells(fnum, 3) = FileLen(MyPath & file.Name)
End If
Next file

'Loop through the files in the Sub Folders if SubFolders = True
If Subfolders = True Then
For Each SubFolderInRoot In RootFolder.Subfolders
For Each file In SubFolderInRoot.Files
If LCase(file.Name) Like LCase(ExtStr) Then
fnum = fnum + 1
Cells(fnum, 1) = MyPath & SubFolderInRoot & "\" & file.Name
Cells(fnum, 2) = FileDateTime(SubFolderInRoot & "\" & file.Name)
Cells(fnum, 3) = FileLen(SubFolderInRoot & "\" & file.Name)
End If
Next file
Next SubFolderInRoot
End If

'If there are no files in the folder display a msgbox
If fnum = 0 Then
MsgBox "There are no " & ExtStr & " files in this folder"
Else

End If
End Sub


--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"answer33" wrote in message ...
Thanks's Ron, but can you be more specific.
I'm not sure what I'm suppose to paste and where to paste it.


"Ron de Bruin" wrote:

Hi

FileSearch is removed from Office 2007 because there where to many problems.

You can use FSO, you can steal a part of the code here to make your loop
http://www.rondebruin.nl/fso.htm



--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"answer33" wrote in message ...
I just switch from Windows XP to Windows 2007 and I'm no longer able to run
this macro.
Can you help me...
Thanks
-----------------------------------------------

Sub ListFiles_01()
'Using FileSearch to list the files in a directory
Dim i As Integer
i = 1
With Application.FileSearch 'This is the problem'
.NewSearch
.LookIn = "C:\"
.Filename = "*.*"
.SearchSubFolders = True
'.SearchFolders = True
.Execute
For i = 1 To .FoundFiles.Count
Range("B" & i + 1).Value = .FoundFiles(i)
Range("C" & i + 1).Value = FileDateTime(.FoundFiles(i))
Range("D" & i + 1).Value = FileLen(.FoundFiles(i))
'Range("E" & i + 1).Value = Filename(.FoundFiles(i))
Next


End With


End Sub



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default update file list code for excel 2007

Thank's a lot Ron,

It works perfeclty!
Have a nice day

"Ron de Bruin" wrote:

You can try something like this

Change MyPath and Subfolders

Sub testme()
Get_File_Names_Test _
MyPath:="C:\Users\Ron\test", _
Subfolders:=False, _
ExtStr:="*.xl*"
End Sub

Sub Get_File_Names_Test(MyPath As String, Subfolders As Boolean, ExtStr As String)
Dim Fso_Obj As Object, RootFolder As Object
Dim SubFolderInRoot As Object, file As Object

Worksheets.Add

'Add a slash at the end if the user forget it
If Right(MyPath, 1) < "\" Then
MyPath = MyPath & "\"
End If

'Create FileSystemObject object
Set Fso_Obj = CreateObject("Scripting.FileSystemObject")

fnum = 0

'Test if the folder exist and set RootFolder
If Fso_Obj.FolderExists(MyPath) = False Then
MsgBox MyPath & " doesn't exist"
Exit Sub
End If
Set RootFolder = Fso_Obj.GetFolder(MyPath)


'Fill the array(myFiles)with the list of Excel files in the folder(s)
'Loop through the files in the RootFolder
For Each file In RootFolder.Files
If LCase(file.Name) Like LCase(ExtStr) Then
fnum = fnum + 1
Cells(fnum, 1) = MyPath & file.Name
Cells(fnum, 2) = FileDateTime(MyPath & file.Name)
Cells(fnum, 3) = FileLen(MyPath & file.Name)
End If
Next file

'Loop through the files in the Sub Folders if SubFolders = True
If Subfolders = True Then
For Each SubFolderInRoot In RootFolder.Subfolders
For Each file In SubFolderInRoot.Files
If LCase(file.Name) Like LCase(ExtStr) Then
fnum = fnum + 1
Cells(fnum, 1) = MyPath & SubFolderInRoot & "\" & file.Name
Cells(fnum, 2) = FileDateTime(SubFolderInRoot & "\" & file.Name)
Cells(fnum, 3) = FileLen(SubFolderInRoot & "\" & file.Name)
End If
Next file
Next SubFolderInRoot
End If

'If there are no files in the folder display a msgbox
If fnum = 0 Then
MsgBox "There are no " & ExtStr & " files in this folder"
Else

End If
End Sub


--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"answer33" wrote in message ...
Thanks's Ron, but can you be more specific.
I'm not sure what I'm suppose to paste and where to paste it.


"Ron de Bruin" wrote:

Hi

FileSearch is removed from Office 2007 because there where to many problems.

You can use FSO, you can steal a part of the code here to make your loop
http://www.rondebruin.nl/fso.htm



--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"answer33" wrote in message ...
I just switch from Windows XP to Windows 2007 and I'm no longer able to run
this macro.
Can you help me...
Thanks
-----------------------------------------------

Sub ListFiles_01()
'Using FileSearch to list the files in a directory
Dim i As Integer
i = 1
With Application.FileSearch 'This is the problem'
.NewSearch
.LookIn = "C:\"
.Filename = "*.*"
.SearchSubFolders = True
'.SearchFolders = True
.Execute
For i = 1 To .FoundFiles.Count
Range("B" & i + 1).Value = .FoundFiles(i)
Range("C" & i + 1).Value = FileDateTime(.FoundFiles(i))
Range("D" & i + 1).Value = FileLen(.FoundFiles(i))
'Range("E" & i + 1).Value = Filename(.FoundFiles(i))
Next


End With


End Sub






  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 230
Default update file list code for excel 2007

On Aug 28, 2:56 pm, "Ron de Bruin" wrote:
Hi

FileSearch is removed from Office 2007 because there where to many problems.


Although not from the help system where it still claims to exist :(

This disaster area claimed as runtime error 5111 is sort of documented
in the KB
http://support.microsoft.com/kb/920229/en-us

Under XP SP2 here it actually dies with runtime 445 - object does not
support this function.

Although their suggested alternative by a scripted bodge method is too
gruesome to contemplate seriously.
Why did they break such a useful general filesearch function?

You can use FSO, you can steal a part of the code here to make your loophttp://www.rondebruin.nl/fso.htm


Thanks for this tip. It should be incorporated into the KB.

Regards,
Martin Brown

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
want to record date for each time I update a file - Excel 2007 PattyR Excel Discussion (Misc queries) 2 June 3rd 09 08:18 PM
Excel 2007 protected file corrupt after update chris l Excel Discussion (Misc queries) 4 January 3rd 08 11:41 PM
Excel cell can't update link in the file in sharepoint 2007 [email protected] Links and Linking in Excel 0 January 3rd 08 12:11 AM
Update back to shaprepoint list from dowloaded Excel file Amitabh Excel Discussion (Misc queries) 0 September 21st 07 09:24 AM
Excel 2007 - Sharpoint 2003 can't update list on server Michael Price Excel Discussion (Misc queries) 3 February 26th 07 03:43 PM


All times are GMT +1. The time now is 05:37 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"