Hello! I'd like to run a macro called "NoFeeAudit" on all xls files in a certain folder and subfolders that contain the word "Current" in the file name.
I'm fairly new to VBA, so I poked around online, and arrived at this:
When I run this, it looks like I'm getting stuck in an infinite loop. No errors/breaks, but no results, either.
Where did I go wrong?
Thanks in advance!
I'm fairly new to VBA, so I poked around online, and arrived at this:
Code:
Sub runMe()
Dim objFSO As Object
Dim objFolder As Object
Dim objFile As Object
Dim MyPath As String
Dim wb As Workbook
With Application
.ScreenUpdating = False
.DisplayAlerts = False
.EnableEvents = False
End With
MyPath = "...\Clients"
Set objFSO = CreateObject("Scripting.FileSystemObject")
'Get the folder object associated with the directory
Set objFolder = objFSO.GetFolder(MyPath)
'Loop through the Files
For Each objFile In objFolder.Files
If InStr(objFile.Name, "~") = 0 _
And InStr(objFile.Name, "Current *") <> 0 And InStr(objFile.Name, ".xls") <> 0 Then
Set wb = Workbooks.Open(objFile, 3)
Application.Run "'" & wb.Name & "'!NoFeeAudit"
wb.Close SaveChanges:=True
End If
Next
With Application
.ScreenUpdating = True
.DisplayAlerts = True
.EnableEvents = True
End With
End Sub
When I run this, it looks like I'm getting stuck in an infinite loop. No errors/breaks, but no results, either.
Where did I go wrong?
Thanks in advance!