Here is another approach for you. Place code in a separate workbook not inside eco system and only run the first sub, which then runs the second sub. This only selects the week, not the year. Let us know if you have questions.
Sub loopAllSubFoldersSelectDirHideWeek()
Dim x As Long
Dim FolderName As String
x = Application.InputBox("Enter the week number you want hidden", , , , , , 1)
With Application.FileDialog(msoFileDialogFolderPicker)
.Title = "Please select the Main folder"
.AllowMultiSelect = False
.Show
FolderName = .SelectedItems(1) & "\"
End With
'Call LoopAllSubFolders("C:\Users\man\OneDrive\Documents\Excel code\TEST\Disp test\", x) 'Use this line to hard code your path if you want
Call loopAllSubFolders(FolderName, x)
MsgBox "Complete"
End Sub
Sub loopAllSubFolders(ByVal folderPath As String, x As Long)
Dim fileName As String
Dim fullFilePath As String
Dim numFolders As Long
Dim folders() As String
Dim i As Long, m&
Dim ws As Worksheet
If Right(folderPath, 1) <> "\" Then folderPath = folderPath & "\"
fileName = Dir(folderPath & "*.*", vbDirectory)
While Len(fileName) <> 0
If Left(fileName, 1) <> "." Then
fullFilePath = folderPath & fileName
If (GetAttr(fullFilePath) And vbDirectory) = vbDirectory Then
ReDim Preserve folders(0 To numFolders) As String
folders(numFolders) = fullFilePath
numFolders = numFolders + 1
Else
Application.Workbooks.Open (folderPath & fileName)
For Each ws In ActiveWorkbook.Sheets
On Error Resume Next
m = 0
m = Application.Match("Week " & x, ws.Range("1:1"), 0)
If m > 0 Then
ws.Columns(m).EntireColumn.Hidden = True
End If
On Error GoTo 0
Next
ActiveWorkbook.Saved = True
Application.DisplayAlerts = False
Workbooks(fileName).Close
Application.DisplayAlerts = True
End If
End If
fileName = Dir()
Wend
For i = 0 To numFolders - 1
loopAllSubFolders folders(i), x
Next i
End Sub
Bookmarks