We have just updated from Excel 2003 to 2010 and the following section of code (from a much longer macro) no longer works due to the removal of Application.Filesearch functionality. Please could someone have a look at the code below and tell me how I should rewrite it? I can read VB and write very simple bits of it but this is beyond me. I have searched the forums and had a go with both Dir and FileSystemObject but I'm afraid I don't understand enough to make it work.
Thanks in advance
'************ determine how many file dealing with ****************************************************
NewFN = Application.GetOpenFilename(FileFilter:="Excel Files (*.xls), *.xls", Title:="Please select a file")
If NewFN = False Then
' They pressed Cancel
MsgBox "Stopping because you did not select a file"
Exit Sub
End If
Workbooks.Open Filename:=NewFN, ReadOnly:=True
myfolder = CurDir
ActiveWorkbook.Close SaveChanges:=False
Set fs = Application.FileSearch
With fs
.LookIn = myfolder
.Filename = "*.xls"
If .Execute(SortBy:=msoSortByFileName, SortOrder:=msoSortOrderAscending) > 0 Then
MsgBox "There were " & .FoundFiles.Count & _
" file(s) found."
For t = 1 To .FoundFiles.Count
myfile = .FoundFiles(t)
Workbooks.Open Filename:=myfile, ReadOnly:=True
Thanks in advance
'************ determine how many file dealing with ****************************************************
NewFN = Application.GetOpenFilename(FileFilter:="Excel Files (*.xls), *.xls", Title:="Please select a file")
If NewFN = False Then
' They pressed Cancel
MsgBox "Stopping because you did not select a file"
Exit Sub
End If
Workbooks.Open Filename:=NewFN, ReadOnly:=True
myfolder = CurDir
ActiveWorkbook.Close SaveChanges:=False
Set fs = Application.FileSearch
With fs
.LookIn = myfolder
.Filename = "*.xls"
If .Execute(SortBy:=msoSortByFileName, SortOrder:=msoSortOrderAscending) > 0 Then
MsgBox "There were " & .FoundFiles.Count & _
" file(s) found."
For t = 1 To .FoundFiles.Count
myfile = .FoundFiles(t)
Workbooks.Open Filename:=myfile, ReadOnly:=True