I've got a boatload of file names that I need to update, and I was trying to do so using the Dir function.
What's weird is that, for some reason, "Dir" is currently returning Error Code 5, "Invalid procedure call or argument."
My code follows; any ideas why it's causing me trouble?
Option Explicit
Dim strPath, strFile, strMon, strFY As String
Dim i As Integer
Sub Populate()
strFY = "FY" & Right(InputBox("What fiscal year?", "FY"), 2)
For i = 1 To 12
Select Case i
Case 1
strMon = "01Jul"
Case 2
strMon = "02Aug"
Case 3
strMon = "03Sep"
Case 4
strMon = "04Oct"
Case 5
strMon = "05Nov"
Case 6
strMon = "06Dec"
Case 7
strMon = "07Jan"
Case 8
strMon = "08Feb"
Case 9
strMon = "09Mar"
Case 10
strMon = "10Apr"
Case 11
strMon = "11May"
Case 12
strMon = "12Jun"
End Select
strPath = ThisWorkbook.Path & "\" & strFY & "\" & strMon & "\"
Dir strPath
While Dir <> ""
If Left(Dir, 5) <> strMon Then
Open strPath & Dir For Random As FreeFile
Workbooks(strPath & Dir).SaveAs Filename:=strMon & Right(Workbooks(Dir).Name, Len(Workbooks(Dir).Name) - 5)
End If
Wend
Next
End Sub
Bookmarks