VBA: auto-wipe all data when date is reached

Herpe_derp

New Member
Joined
Jun 21, 2023
Messages
9
Office Version
  1. 365
Platform
  1. Windows
Is there some VBA code that can password protect a workbook when a certain date is reached so the data cannot be viewed or edited by anyone without the password?
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Your description of your question does not seem to match your title (your title talks about auto-wiping data, where your question just talks about password protecting it - those are two totally different things, and if you "wipe" the data, password protection really isn't necessary as there will be nothing to see!) So I think we may need some clarification there.

Regarding password protecting the file, it can be done, but I would not count on it.
Excel security is notoriously weak and is VERY easy to break without too much effort by anyone willing to do a little research on the internet.

At best, it acts as a deterement and protects against the "accidental" attempts to see what a user shouldn't.
But it will not prevent anyone motivated to hack it.

So if security is an important piece of this project, Excel is not your best option.
 
Upvote 0
Your description of your question does not seem to match your title (your title talks about auto-wiping data, where your question just talks about password protecting it - those are two totally different things, and if you "wipe" the data, password protection really isn't necessary as there will be nothing to see!) So I think we may need some clarification there.

Regarding password protecting the file, it can be done, but I would not count on it.
Excel security is notoriously weak and is VERY easy to break without too much effort by anyone willing to do a little research on the internet.

At best, it acts as a deterement and protects against the "accidental" attempts to see what a user shouldn't.
But it will not prevent anyone motivated to hack it.

So if security is an important piece of this project, Excel is not your best option.
Hi, you’re right. Changed my mind but forgot to edit the title. Apologies.

The password protect option is the best in my situation as it’s only needed to protect from basic users.

Kind Regards
 
Upvote 0
Your description of your question does not seem to match your title (your title talks about auto-wiping data, where your question just talks about password protecting it - those are two totally different things, and if you "wipe" the data, password protection really isn't necessary as there will be nothing to see!) So I think we may need some clarification there.

Regarding password protecting the file, it can be done, but I would not count on it.
Excel security is notoriously weak and is VERY easy to break without too much effort by anyone willing to do a little research on the internet.

At best, it acts as a deterement and protects against the "accidental" attempts to see what a user shouldn't.
But it will not prevent anyone motivated to hack it.

So if security is an important piece of this project, Excel is not your best option.
Could someone also provide the wipe option too?
 
Upvote 0
Could someone also provide the wipe option too?
You could do something like this, putting the following code in the "ThisWorkbook" module so it runs automatically when the file is opened:
VBA Code:
Private Sub Workbook_Open()

    Dim ws As Worksheet

'   Check to see if specified date is passed
    If Date >= DateSerial(2023, 6, 29) 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

You would just need to change the date inside here:
VBA Code:
DateSerial(2023, 6, 29)
to match the date you want to use.

Note: There is a BIG caveat here. If the user does NOT enable VBA/Macros on this workbook, the code will never run. So it is super easy to bypass (whether intentional or accidental).
What I have seen some users do is use a "BeforeClose" event to hide most sheets upon closing. Then add code to the "Open" event above to then unhide the sheets.
So if they do not enable Macros/VBA, all but one sheet will be hiddent when opened.
Once again, not foolproof, and easy to get around by anyone motivated enough. Really just designed to prevent honest users from doing things they shouldn't accidentally be doing.
 
Upvote 1

Forum statistics

Threads
1,223,630
Messages
6,173,456
Members
452,514
Latest member
cjkelly15

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top