Search ".xls" files and then CUT and PASTE to new location

afzalw

New Member
Joined
Jul 24, 2012
Messages
20
I have a folder with many subfolders and I want to search ".xls" files from these subfolders and then cut and paste them to new location. There is a code available over interned for searching files in folder but apparently it does not work in newer versions of Excel.
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
Code:
Sub FileFindInSubfolders()
   Dim StrFile As String, objFSO, destRow As Long
   Dim mainFolder, mySubFolder
   mFolder = Range("B2").Value ' folder
   fname = Range("B3").Value ' file name
   Set objFSO = CreateObject("Scripting.FileSystemObject")
   mFolder = "D:\DATI\prova\"
   Set mainFolder = objFSO.GetFolder(mFolder)
   StrFile = Dir(mFolder & "\" & fname)
   If StrFile <> "" Then
      MsgBox mFolder & "\" & StrFile & " found"
   Else
     For Each mySubFolder In mainFolder.SubFolders
       StrFile = Dir(mySubFolder & "\" & fname)
       If StrFile <> "" Then
          MsgBox mySubFolder & "\" & StrFile & " found"
          Exit For
       End If
     Next
   End If
End Sub
 
Upvote 0
Patel45 code extracts paths from the subfolders but does not copy or move them where as dmt32 code does not go in sub folders of main folders. Looks like I need something have the combination of these two codes.
 
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