Herpe_derp
New Member
- Joined
- Jun 21, 2023
- Messages
- 9
- Office Version
- 365
- Platform
- Windows
Hello
My code is set to wipe a workbook based on a date
Private Sub Workbook_Open()
Dim ws As Worksheet
' Check to see if specified date is passed
If Date >= DateSerial(2023, 7, 6) Then
' If it is, loop through all sheets
For Each ws In ActiveWorkbook.Worksheets
' Clear contents of each sheet
ws.Cells.ClearContents
Next ws
' Save workbook so data is permanently gone
ActiveWorkbook.Save
End If
End Sub
However, this is struggling to work on password protected sheets. Is there any way it can be modified to unprotect sheets before running?
The debug highlights ws.Cells.ClearContents yellow
My code is set to wipe a workbook based on a date
Private Sub Workbook_Open()
Dim ws As Worksheet
' Check to see if specified date is passed
If Date >= DateSerial(2023, 7, 6) Then
' If it is, loop through all sheets
For Each ws In ActiveWorkbook.Worksheets
' Clear contents of each sheet
ws.Cells.ClearContents
Next ws
' Save workbook so data is permanently gone
ActiveWorkbook.Save
End If
End Sub
However, this is struggling to work on password protected sheets. Is there any way it can be modified to unprotect sheets before running?
The debug highlights ws.Cells.ClearContents yellow