Application.FileSearch - converting to Excel 2007

poiu

Active Member
Joined
Sep 13, 2011
Messages
384
Hello,

I've googled this and gone through the relevent threads but can't get my head around the fix for this. Please could you tell me how to go about converting the below code from Excel 2003 to Excel 2007 (it's the problem of the Application.FileSearch function being deprecated).

I've inherited the code but basically it goes into a folder open each file in turn and collects the comments from a "comments" tab and puts into a master file.

Thanks for your help,

Poiu


Sub Test()
With Application.FileSearch
.NewSearch
.LookIn = "\\bnls614f\bnlsangroup2\FolderName\P" & Range("Period") & "\Comments - HR"
.SearchSubFolders = False
.Filename = "*.xls"
.Execute

For I = 1 To .FoundFiles.Count
'Open each workbook
Set wb = Workbooks.Open(Filename:=.FoundFiles(I))

wbs = ActiveWorkbook.Name
' Unprotect the workbook
ActiveWorkbook.Unprotect Password:="Password"

Sheets("Comments").Visible = True
Sheets("MapGICCandCOA (2)").Visible = True
Sheets("Comments").Select

' Take all historic (and current month) comments from the first file,
' and only current month comments from the other files (Prevents
' overload due to the number of comment records)
If (I > 1) Then
Selection.AutoFilter Field:=7, Criteria1:=intPeriod
End If

LastRow1 = Range("A65536").End(xlUp).Row
Range("A1:J" & LastRow1).Select
Selection.SpecialCells(xlCellTypeVisible).Select

Selection.Copy

Workbooks("Allcomments - HR function only.xls").Activate
ActiveWorkbook.Worksheets("Comments").Select
LastRow = Range("A65536").End(xlUp).Row
Cells(LastRow + 1, 1).Select
ActiveSheet.Paste
Application.CutCopyMode = False

Workbooks(wbs).Activate
Application.CutCopyMode = False
Workbooks(wbs).Close

' Reprotect the workbook
ActiveWorkbook.Protect Password:="Password"

Next I

End With
End Sub
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
You need to look at the DIR Command there are plenty of examples here in the forum.
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top