Protect Excel VBA Code and workbook

nando88

Board Regular
Joined
Jun 22, 2013
Messages
124
I would like to distribute my excel workbook to other people, and I was wondering if there's a way to protect my VBA code so that it would be hard to hack, and also make my workbook work as a trial, so that after a certain amount of time, it wont open anymore?
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
you can password the vba side, and set an end date:

Code:
Private Sub Workbook_Open()
If Date > #1/24/2022# Then
  MsgBox "Trial has ended."
  ActiveWorkbook.Close False
End If
End Sub
 
Upvote 0
To protect your macros, you have to protect your VBA Project. Do the following:
-hold down the ALT key and press the F11 key to open the Visual Basic Editor
-click on 'Tools' on the top menu
-click 'VBAProject Properties'
-click the 'Protection' tab
-click the box to the left of 'Lock project for viewing' to put a check mark in it
-enter your password and then confirm it and click 'OK'
-close the VB Editor
-save your workbook as a macro-enabled file and close it
When you re-open the file, you will not be able to see the macros unless you enter the password. Keep in mind that this type of protection is not very strong and anyone who really wants to get at your macros can probably do it with a little research. I hope this helps.
 
Upvote 0
you can password the vba side, and set an end date:

Code:
Private Sub Workbook_Open()
If Date > #1/24/2022# Then
  MsgBox "Trial has ended."
  ActiveWorkbook.Close False
End If
End Sub
Unfortunately, that does not really meet the criteria of making it "hard to hack", as all they have to do is disable VBA before opening the workbook, and that code will not run.
 
Upvote 0
you can password the vba side, and set an end date:

Code:
Private Sub Workbook_Open()
If Date > #1/24/2022# Then
  MsgBox "Trial has ended."
  ActiveWorkbook.Close False
End If
End Sub

How would I make this code automatic, so that I just set a number of days since the workbook was first opened, and when that date is finally reached, the workbook closes automatically, without me having to hard code the date?
 
Upvote 0
I would like an opinion on this solution I found online:
Prohibiting the File from Opening if Macros are Disabled?
They suggest hiding all the sheets except one on close, that will have a message for the user like: trial expired, and when you open the file, the sheets will be unhidden through vba.
The workbook would also be protected.
My question is if the sheets can be unhidden even if VBA is disabled.
 
Upvote 0

Forum statistics

Threads
1,215,577
Messages
6,125,637
Members
449,242
Latest member
Mari_mariou

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