Hello!
I have to remove all data from multiple files and delete everything that is hidden, so I am looking for a macro that first it will remove all formulas (paste as values) from the files in folders and subfolders, afterwards remove hidden sheets, rows and columns.
I have found an old thread closest to my situation. Can anyone help me with the modifications?
Thank you very much!
I have to remove all data from multiple files and delete everything that is hidden, so I am looking for a macro that first it will remove all formulas (paste as values) from the files in folders and subfolders, afterwards remove hidden sheets, rows and columns.
I have found an old thread closest to my situation. Can anyone help me with the modifications?
VBA Code:
Sub RemoveFormulas()
Dim fName$, wkb As Workbook, wks As Worksheet
Const folder_path$ = "C:\Temp\Test\"
Dim fso As Object, fld As Object, fl As Object
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Set fso = CreateObject("Scripting.FileSystemObject")
Call ProcessFolder(fso.GetFolder(folder_path))
Application.DisplayAlerts = True
Application.ScreenUpdating = True
MsgBox "Well done!", vbInformation
End Sub
Private Sub ProcessFolder(fld As Object)
Dim fl As Object, subfld As Object
For Each fl In fld.Files
Call RemoveFormulasInternal(fl.Path)
Next
If fld.SubFolders.Count > 0 Then
For Each subfld In fld.SubFolders
Call ProcessFolder(subfld)
Next
End If
End Sub
Private Sub RemoveFormulasInternal(file_path$)
Dim wkb As Workbook, wks As Worksheet
Set wkb = Workbooks.Open(file_path, UpdateLinks:=False)
For Each wks In wkb.Sheets
wks.Range("A1:AZ100").Copy
wks.Range("A1").PasteSpecial xlPasteValues
Application.CutCopyMode = False
Next
wkb.Close SaveChanges:=True
End Sub
Thank you very much!