Hi everyone, I am trying to write a VBA code that runs through a directory of excel files of the same format, that unhides and unlinks all the sheets.
I was able to make the unhide and unlink portion work, but running it through the directory is where I am getting stuck.
I open the first file in the directory, try to run the macro and excel shuts down. I have 90p files in the directory, and each file is about 2MB
Here is the code I have written till now -
Sub DirectoryFileLoopUnhideAndUnlink()
Dim fileDirectory As String
Dim fileCriteria As String
Dim fileName As String
Dim fileToOpen As Workbook
Application.ScreenUpdating = False
fileDirectory = "C:\Users\Downloads\TEST Loop\"
fileName = Dir(fileDirectory)
Do While Len(fileName) > 0
For Each Sheet In Sheets
Sheet.Visible = True
Next Sheet
Sheets("ABBrand").Select
Range("D17").Select
ActiveSheet.ListObjects("Brand").Unlink
Sheets("ABItem").Select
Range("J11").Select
ActiveSheet.ListObjects("Item").Unlink
Loop
Application.ScreenUpdating = True
End Sub
Can you please let me know what I am doing wrong?
I was able to make the unhide and unlink portion work, but running it through the directory is where I am getting stuck.
I open the first file in the directory, try to run the macro and excel shuts down. I have 90p files in the directory, and each file is about 2MB
Here is the code I have written till now -
Sub DirectoryFileLoopUnhideAndUnlink()
Dim fileDirectory As String
Dim fileCriteria As String
Dim fileName As String
Dim fileToOpen As Workbook
Application.ScreenUpdating = False
fileDirectory = "C:\Users\Downloads\TEST Loop\"
fileName = Dir(fileDirectory)
Do While Len(fileName) > 0
For Each Sheet In Sheets
Sheet.Visible = True
Next Sheet
Sheets("ABBrand").Select
Range("D17").Select
ActiveSheet.ListObjects("Brand").Unlink
Sheets("ABItem").Select
Range("J11").Select
ActiveSheet.ListObjects("Item").Unlink
Loop
Application.ScreenUpdating = True
End Sub
Can you please let me know what I am doing wrong?