PC Review


Reply
Thread Tools Rate Thread

Application.FileSearch in 2007

 
 
Amery
Guest
Posts: n/a
 
      13th Dec 2007
I have a batch of code that works for any computer with 2003 or earlier
versions, and I have been told by 2007 that it no longer is allowed. Here's
the code..

dim fs as variant
Set fs = Application.FileSearch
With fs
.LookIn = Sheet2.Cells(6, 4)
.Filename = "*.xls"
If .Execute(SortBy:=msoSortByFileName, SortOrder:=msoSortOrderAscending)
> 0 Then

end if
End With

The code breaks at the set command and says something regarding the fact
that 2007 no longer supports the method or object. Does anyone know of a way
to get this to work in Excel '07?
 
Reply With Quote
 
 
 
 
Jon Peltier
Guest
Posts: n/a
 
      13th Dec 2007
You could use the FileSystemObject:

http://support.microsoft.com/kb/185601
http://www.vb-helper.com/howto_list_...hierarchy.html
http://www.vbaexpress.com/kb/getarticle.php?kb_id=232

for more:
http://www.google.com/search?ie=UTF-...ory+search+fso

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Tutorials and Custom Solutions
Peltier Technical Services, Inc. - http://PeltierTech.com
_______


"Amery" <(E-Mail Removed)> wrote in message
news:CA7EA664-E487-4CA0-A1F2-(E-Mail Removed)...
>I have a batch of code that works for any computer with 2003 or earlier
> versions, and I have been told by 2007 that it no longer is allowed.
> Here's
> the code..
>
> dim fs as variant
> Set fs = Application.FileSearch
> With fs
> .LookIn = Sheet2.Cells(6, 4)
> .Filename = "*.xls"
> If .Execute(SortBy:=msoSortByFileName,
> SortOrder:=msoSortOrderAscending)
>> 0 Then

> end if
> End With
>
> The code breaks at the set command and says something regarding the fact
> that 2007 no longer supports the method or object. Does anyone know of a
> way
> to get this to work in Excel '07?



 
Reply With Quote
 
ilia
Guest
Posts: n/a
 
      13th Dec 2007
It's a little clumsier with the Dir function. This function will
return a 2D variant array of file names listed in ascending sorted
order, in a directory. Sub Test() demonstrates usage:

Public Sub test()
Dim v As Variant

v = getDir(Sheet2.Cells(6, 4))
' print the last file name in the list
Debug.Print v(UBound(v), 1)
End Sub


Public Function getDir(path As String) As Variant
Dim fList() As String
Dim iPosition As Long
Dim iSize As Long
Dim sFile As String
Dim fRange As Excel.Range
Const iIncrement As Long = 50

iSize = iIncrement
ReDim fList(1 To iSize)

sFile = Dir(path & _
IIf(Right(path, 1) = "\", "", "\") & _
"*.xls")

Do While Len(sFile)
iPosition = iPosition + 1
If iPosition > iSize Then
iSize = iSize + iIncrement
ReDim Preserve fList(1 To iSize)
End If
fList(iPosition) = sFile
sFile = Dir
Loop

If iSize > iPosition Then
ReDim Preserve fList(1 To iPosition)
End If

Set fRange = Sheet2.Range("E1").Resize(iPosition, 1)
fRange.Value = WorksheetFunction.Transpose(fList)

fRange.Sort key1:=fRange.Cells(1), order1:=xlAscending
getDir = fRange.Value
fRange.Clear
End Function




On Dec 13, 4:23 pm, Amery <Am...@discussions.microsoft.com> wrote:
> I have a batch of code that works for any computer with 2003 or earlier
> versions, and I have been told by 2007 that it no longer is allowed. Here's
> the code..
>
> dim fs as variant
> Set fs = Application.FileSearch
> With fs
> .LookIn = Sheet2.Cells(6, 4)
> .Filename = "*.xls"
> If .Execute(SortBy:=msoSortByFileName, SortOrder:=msoSortOrderAscending)> 0 Then
>
> end if
> End With
>
> The code breaks at the set command and says something regarding the fact
> that 2007 no longer supports the method or object. Does anyone know of a way
> to get this to work in Excel '07?


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Application.FileSearch 2007 Reference Justin Microsoft Access Form Coding 1 9th Dec 2009 11:30 PM
Using Application.FileSearch in Access 2007 Chip Microsoft Access External Data 5 4th Nov 2009 01:00 AM
Application.FileSearch in Excel 2007! Mark Microsoft Excel Discussion 3 24th Jun 2009 04:56 PM
Application.FileSearch 2003 vs 2007 Sgwapt Microsoft Excel Programming 1 20th Jun 2008 09:12 AM
replacement for Application.FileSearch in 2007 =?Utf-8?B?U3RldmVEQjE=?= Microsoft Excel Programming 1 11th Jul 2007 06:28 PM


Features
 

Advertising
 

Newsgroups
 


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