Hi all
Any assistance greatly appreciated here.
I am struggling to understand why this code isn't working. Any ideas?
If it helps at all, the folder location is on a network and the macro I'm calling is located in the same file as this macro.
Cheers.
And the files in the folder that I am looping through have the CSV extension.
Any assistance greatly appreciated here.
I am struggling to understand why this code isn't working. Any ideas?
Code:
Sub RunCodeOnAllXLSFiles()
Dim lCount As Long
Dim wbResults As Workbook
Dim wbCodeBook As Workbook
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Application.EnableEvents = False
On Error Resume Next
Set wbCodeBook = ThisWorkbook
With Application.FileSearch
.NewSearch
'Change path to suit
.LookIn = "N:\1 Projects\2 Active\003711 RIO Tinto Rail Access RSA, WA\4-Working\Rating Output\POI"
.FileType = msoFileTypeExcelWorkbooks
'Optional filter with wildcard
'.Filename = "Book*.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
Set wbResults = Workbooks.Open(Filename:=.FoundFiles(lCount), UpdateLinks:=0)
'DO YOUR CODE HERE
Application.Run ("CreatePOI")
wbResults.Close SaveChanges:=False
Next lCount
End If
End With
On Error GoTo 0
Application.ScreenUpdating = True
Application.DisplayAlerts = True
Application.EnableEvents = True
End Sub
If it helps at all, the folder location is on a network and the macro I'm calling is located in the same file as this macro.
Cheers.
And the files in the folder that I am looping through have the CSV extension.
Last edited: