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

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
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,220,965
Messages
6,157,119
Members
451,399
Latest member
alchavar

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