1

I'm a VBA beginner. An excel of the company has already been well edited with multiple macros long time ago and it will be used by our clients. The problem is we want to block their utilisation of macros in several months after the project is finished. Is there a simple way that all macros will be deactivated when coming to a specific date or a password of protection will be activated from a certain date? Thank you in advance !

Pᴇʜ
  • 56,719
  • 10
  • 49
  • 73

1 Answers1

0

You could implement a Sub which does a RaiseError if the date is later than a certain value, then call this Sub from all your macros as their very first operation.

Now, when you provide these functionalities to the clients/users, you will only have to override the date you compare the current date with.

This is how you can get today's date in VBA: https://www.automateexcel.com/vba/todays-current-date/ This is how you can compare two dates in VBA: Compare Dates in VBA

Lajos Arpad
  • 64,414
  • 37
  • 100
  • 175
  • Thanks a lot, I think this will work ! – Jing yu Zhang Feb 03 '22 at 13:12
  • @JingyuZhang you are welcome! If this answer has led you to the solution, then you might consider accepting it as the correct answer. – Lajos Arpad Feb 03 '22 at 13:18
  • 1
    Note that this is only a way to obscure but not to secure. There are ways around that and there is no way to securly prevent the use of the macros after that day. Any experienced user will be able to overcome such a solution. – Pᴇʜ Feb 03 '22 at 13:58
  • @Pᴇʜ yes, that's correct, this is just an easy way to put a blocker. Is there a better (easy) way that you would recommend? – Lajos Arpad Feb 03 '22 at 14:03
  • 1
    @LajosArpad I think there is actually no safe way to accomplish that on client side. Since the user can always change back the time settings on his computer. The only way I can imagine is having a server that is checked if the license is still valid. The server time cannot be changed by a client and the server gives a reliable answer valid/invalid. If the VBA code is then additionally secured with a password, so it cannot be changed/viewed easily that might be kinda safe as it can be with VBA. Still you need a secure way to communicate with the server, otherwise it could be emulated. – Pᴇʜ Feb 03 '22 at 14:13
  • @Pᴇʜ yes, I agree with you. The question is about having an easy way to add a blocker. This is an easy way to do so, even though experienced people can overcome it. Non-programmers would have to set back their date, but it's such an uncomfortable approach (because it would affect their other applications) that some will rather pay for a license. Yes, one could install a virtual machine and use the application from there, that way the other applications would not be affected. Also, even binary files can be hacked, via Assembly in the worst case, so the safest is to create a license at server. – Lajos Arpad Feb 03 '22 at 14:28
  • @Pᴇʜ yet, whenever files are downloaded to the client, they can be modified by the client. – Lajos Arpad Feb 03 '22 at 14:29
  • @LajosArpad I didn't mean to discredit your approach. I just wanted to prevent that anyone thinks it is a perfectly secure solution. If the OP knows what he is implementing and he knows where the gaps are and he's okay with that, then I totally aggree that this might be an easy solution, so why not to use it. I mean most software can be cracked as you already said. – Pᴇʜ Feb 03 '22 at 14:44
  • Thanks for all the comments. As an additional comment for this approach, I think it's simple to select "Lock project from viewing" by using a password in order to prevent users from modifying the date limites. – Jing yu Zhang Feb 04 '22 at 14:34
  • @JingyuZhang yes, as PEH pointed out, this is not a totally safe approach, but it makes it more difficult to use it when the license expires. Your additional password-protection is also an improvement. – Lajos Arpad Feb 05 '22 at 14:17