Excel 2010: VBA replacement for Application.FileSearch

vendetta81

New Member
Joined
Jun 27, 2012
Messages
5
Hi!

First off I am a noob at VBA and I have been trying to fix this issue myself by reading other threads. Sucks Application.Filesearch is gone, I could at least figure that coding out. It is not going very well. The following code is pasted below. If somebody is kind enough to please provide me a solution for this code. Many thanks in advance!!!



With Application.FileSearch
.NewSearch
.LookIn = Path4
.FileType = msoFileTypeWordDocuments
If .Execute > 0 Then
'if word docs are present in the folder
Workbooks.Open Main4 & Form4
Application.Run "'C:\MISC\Macro.xls'!Module.Start"
Workbooks(Form4).Close savechanges:=True
Workbooks(FormResults4).Close savechanges:=True
Else
End If
End With
 
Hi merveak,

The following example shows how to use the function. It was extracted from the code.

Code:
[FONT="Consolas"][SIZE="2"][COLOR="Navy"][COLOR="Green"]' Using the function (sample code)[/COLOR]
[COLOR="Green"]' --------------------------------[/COLOR]
[COLOR="Green"]'    Dim iFilesNum As Integer[/COLOR]
[COLOR="Green"]'    Dim iCount As Integer[/COLOR]
[COLOR="Green"]'    Dim recMyFiles() As FoundFileInfo[/COLOR]
[COLOR="Green"]'    Dim blFilesFound As Boolean[/COLOR]
[COLOR="Green"]'[/COLOR]
[COLOR="Green"]'    blFilesFound = FindFiles("C:\Users\MBA\Desktop", _[/COLOR]
[COLOR="Green"]'        recMyFiles, iFilesNum, "*.txt?", True)[/COLOR]
[COLOR="Green"]'    If blFilesFound Then[/COLOR]
[COLOR="Green"]'        For iCount = 1 To iFilesNum[/COLOR]
[COLOR="Green"]'            With recMyFiles(iCount)[/COLOR]
[COLOR="Green"]'                MsgBox "Path:" & vbTab & .sPath & _[/COLOR]
[COLOR="Green"]'                    vbNewLine & "Name:" & vbTab & .sName, _[/COLOR]
[COLOR="Green"]'                    vbInformation, "Found Files"[/COLOR]
[COLOR="Green"]'            End With[/COLOR]
[COLOR="Green"]'        Next[/COLOR]
[COLOR="Green"]'    Else[/COLOR]
[COLOR="Green"]'        MsgBox "No file(s) found matching the specified file spec.", _[/COLOR]
[COLOR="Green"]'            vbInformation, "File(s) not Found"[/COLOR]
[COLOR="Green"]'    End If[/COLOR]
[COLOR="Green"]'[/COLOR][/SIZE][/FONT]
[/COLOR]
As you can see from the sample code, you have to call the function and then test the return value; if it is true this means files were found, otherwise nothing found.

If files were found, the number of found files will be in iFilesNum and the list of files (path and name) in recMyFiles.

To use the function properly, you have to copy all the code to a module. The latest code is in post #15.

If you are looking for code to send e-mail with attachments then this is not the right thread and would recommend opening new thread for this purpose.

Regards
 
Upvote 0

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Hi @Mohammad Basem - WOW great code, thanks for sharing this. Thumbs up.

How could I use your code to search and select the biggest file in the selected folder? Like I want to single out the biggest .jpg of all found files.

Regards!
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,337
Members
452,637
Latest member
Ezio2866

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