Application.FileSearch Replacement Error Help

PA1988

New Member
Joined
Mar 13, 2014
Messages
2
Hello,<o:p></o:p>
Iam a fairly big VBA noob and have been searching many forums for an answer tomy problem. I am having an issue with the application.filesearch in 2003 notworking in 2007/2013. I was wondering if anybody could help me re-write thecode to work in Office 2013. The code is pretty basic. Any help would begreatly appreciated. I believe the "find files" is the only sectionthat needs updated. Thanks in advance for your help!<o:p></o:p>
SubDatabase() Dim fn, m, d, X, c<o:p></o:p>
IfDay(Now()) = 1 Then Select Case Month(Now() - 10) Case Is = 1 X ="January" Case Is = 2 X = "February" Case Is = 3 X ="March" Case Is = 4 X = "April" Case Is = 5 X ="May" Case Is = 6 X = "June" Case Is = 7 X ="July" Case Is = 8 X = "August" Case Is = 9 X ="September" Case Is = 10 X = "October" Case Is = 11 X ="November" Case Is = 12 X = "December" End Select<o:p></o:p>
ElseSelect Case Month(Now()) Case Is = 1 X = "January" Case Is = 2 X ="February" Case Is = 3 X = "March" Case Is = 4 X ="April" Case Is = 5 X = "May" Case Is = 6 X ="June" Case Is = 7 X = "July" Case Is = 8 X ="August" Case Is = 9 X = "September" Case Is = 10 X ="October" Case Is = 11 X = "November" Case Is = 12 X ="December" End Select End If<o:p></o:p>
Sheets("Database").Cells(45,1).Resize(65000, 15).ClearContents Sheets("Non Prod Database").Cells(30,1).Resize(65000, 5).ClearContents<o:p></o:p>
'''''''''''''''''''''''Find Files WithApplication.FileSearch .NewSearch .LookIn = "S:\Corr\Corr".SearchSubFolders = True .Filename = X .MatchTextExactly = True .FileType =msoFileTypeAllFiles If .Execute() > 0 Then'''''''Import Into Excel For i = 1 To.FoundFiles.Count<o:p></o:p>
fn = .FoundFiles(i)<o:p></o:p>
<o:p> </o:p>
Workbooks.OpenFilename:=fn, ReadOnly:=True<o:p></o:p>
fn = ActiveWorkbook.Name<o:p></o:p>
For d = 2 ToWorksheets.Count<o:p></o:p>
Sheets(d).Select<o:p></o:p>
Cells(5, 2).Select<o:p></o:p>
If Cells(5, 2) = "" And Cells(6, 11)= "" Then<o:p></o:p>
GoTo Nextd1<o:p></o:p>
End If<o:p></o:p>
ActiveSheet.Unprotect<o:p></o:p>
c = Cells(1,8).Value<o:p></o:p>
Selection.CurrentRegion.Select<o:p></o:p>
Selection.Offset(2,0).Resize(Selection.Rows.Count - (92 - c), Selection.Columns.Count - 3).Select<o:p></o:p>
Selection.Copy<o:p></o:p>
ThisWorkbook.Activate<o:p></o:p>
Sheets("Database").Activate<o:p></o:p>
Range("A45").Select<o:p></o:p>
IfRange("A45") = "" Or Range("A46") = ""Then<o:p></o:p>
ActiveCell.Offset(0,1).Select<o:p></o:p>
Else<o:p></o:p>
Selection.End(xlDown).Select<o:p></o:p>
ActiveCell.Offset(1, 1).Select<o:p></o:p>
End If<o:p></o:p>
Selection.PasteSpecial Paste:=xlValues<o:p></o:p>
Application.CutCopyMode = False<o:p></o:p>
Selection.Resize(Selection.Rows.Count + 1, 1).Offset(0, -1).Select<o:p></o:p>
Selection.Value =Workbooks(fn).Name<o:p></o:p>
Selection.Offset(Selection.Rows.Count - 1, 10).Resize(1, 1).Select<o:p></o:p>
Selection =Workbooks(fn).ActiveSheet.Cells(6, 11)<o:p></o:p>
Workbooks(fn).Activate<o:p></o:p>
Cells(12,11).Resize(35, 2).Select<o:p></o:p>
Selection.Copy<o:p></o:p>
ThisWorkbook.Activate<o:p></o:p>
Sheets("NonProd Database").Activate<o:p></o:p>
Range("A27").Select<o:p></o:p>
IfRange("A27") = "" Or Range("A28") = ""Then<o:p></o:p>
ActiveCell.Offset(0,1).Select<o:p></o:p>
Else<o:p></o:p>
Selection.End(xlDown).Select<o:p></o:p>
ActiveCell.Offset(1, 1).Select<o:p></o:p>
End If<o:p></o:p>
Selection.PasteSpecial Paste:=xlValues<o:p></o:p>
Application.CutCopyMode = False<o:p></o:p>
Selection.Resize(Selection.Rows.Count + 1, 1).Offset(0, -1).Select<o:p></o:p>
Selection.Value =Workbooks(fn).Name<o:p></o:p>
Workbooks(fn).Activate<o:p></o:p>
<o:p> </o:p>
 

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