I have a problem with running this excel 2003 vba code in new 2007 excel versions. The problem is that application.FileSearch does not work in the new versions.
After much time spent searching the Internet I cannot find a solution or work out how to adapt my code so I have had to give in and seek help from others!
The function of this code is to search through all folders and sub-folders in a specified directory. The filename is checked and if it matches a variable “Part Number” it is opened. Once opened it is renamed Doner.
This process continues searching through the folders and sub-folders checking filename by variable until all variables have been checked.
Hope somebody can help, been trying to sort this myself but just don’t know how. Any questions just ask, cheers.
After much time spent searching the Internet I cannot find a solution or work out how to adapt my code so I have had to give in and seek help from others!
The function of this code is to search through all folders and sub-folders in a specified directory. The filename is checked and if it matches a variable “Part Number” it is opened. Once opened it is renamed Doner.
This process continues searching through the folders and sub-folders checking filename by variable until all variables have been checked.
Code:
Sub Import()
Dim lCount As Long
Dim wbResults As Workbook
Dim wbCodeBook As Workbook
Dim DOS As Variant
Dim Delimiter As String
Dim rngCel As Range
Dim rFound As Range
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Application.EnableEvents = False
Set wbCodeBook = ThisWorkbook
With Application.FileSearch
.NewSearch
'Change path to suit
.LookIn = “\\PATH\Path1\Path\”
.SearchSubFolders = True
.FileType = msoFileTypeExcelWorkbooks
.Filename = "*" & Part_Number & "*.xls"
If .Execute > 0 Then 'Workbooks in folder
For lCount = 1 To .FoundFiles.count 'Loop through all.
'Open Workbook x and Set a Workbook variable to it
DOS = GetFilenameFromPath(.FoundFiles(lCount))
Delimiter = "^"
PartNumber = GetElement2(DOS, 2, Delimiter)
Set wbResults = Workbooks.Open(Filename:=.FoundFiles(lCount), UpdateLinks:=0)
Doner = ActiveWorkbook.Name
Hope somebody can help, been trying to sort this myself but just don’t know how. Any questions just ask, cheers.