Consulting

Results 1 to 15 of 15

Thread: How to encrypt vba code on the fly

  1. #1

    How to encrypt vba code on the fly

    hello
    (excuse my bad english)

    i try to make a sub to encrypt the vba code when the wbook is open
    something like:
    Sun WorkBook_Open()
    encrypt
    ....all the vba code in the project
    En Sub
    so when the user of the wbook do ALT+F11
    what he is viewing looks like:

    Sub TEst()
    20610 9280 20610 9280 22367 9280 9222 9280 23198 21741 29204 28763
    End Sub
    Is it possible?

  2. #2
    I just realize that if the user deactivate the macro
    he can see the code
    so my question is stupid
    I just want to hide the code to avoid the user to alter the code.
    I don't want to put a password in the VBAProject
    Perhaps somebody has tips to arrive to the same result of what i want to do.

  3. #3
    VBAX Regular
    Joined
    May 2004
    Location
    Sydney, Australia
    Posts
    36
    Location
    Hi,

    Why can't you use a password? That is the most reliable and simple way of stopping someone else from changing your code. An alternative is to share your workbook (Tools, Share Workbook) as this prevents anyone from editing or viewing your code.

    Hope this helps,
    Daniel

  4. #4
    Site Admin
    Jedi Master
    VBAX Guru Jacob Hilderbrand's Avatar
    Joined
    Jun 2004
    Location
    Roseville, CA
    Posts
    3,712
    Location
    1. In VBE goto Tools | VBE Project Properties...
    2. Select the Protection tab
    3. Check the box for "Lock project for viewing"
    4. Input and confirm your password
    5. Save and close the workbook

  5. #5
    Because thera utilities on the net to brek VBA password
    I just want to make the code unreadable

  6. #6
    VBAX Tutor
    Joined
    May 2004
    Location
    Germany, Dresden
    Posts
    217
    Location
    And how will the encrypted code be executed? Even if you could encrypt the whole code, you'll still need unencrypted parts to execute at least the encryption. And if the user can read this encryption code...

  7. #7
    Site Admin
    Urban Myth
    VBAX Guru
    Joined
    May 2004
    Location
    Oregon, United States
    Posts
    4,940
    Location
    One fact that we must all live with (for now) is that Excel is just not that secure. Nothing in this world ever is - but especially Excel! It wasn't designed that way. If you protect it, there will always be those out there who can break into it within two minutes, that's just a fact of life.

    Imho, the VBA password is probably the best way to disallow users to view your code.

  8. #8
    BoardCoder
    Licensed Coder VBAX Expert mark007's Avatar
    Joined
    May 2004
    Location
    Leeds, UK
    Posts
    622
    Location
    The best way would be to compile your code to COM and run it as a COM addin if you are that worried.

    "Computers are useless. They can only give you answers." - Pablo Picasso
    Mark Rowlinson FIA | The Code Net

  9. #9
    Site Admin
    Jedi Master
    VBAX Guru Jacob Hilderbrand's Avatar
    Joined
    Jun 2004
    Location
    Roseville, CA
    Posts
    3,712
    Location
    If you just want to stop users from accidentally messing up the code, a password on the project is sufficient. For some added security you can make a COM addin like Mark suggests. If you really want better security, then don't use Excel at all. It really is not meant to be secure at all.

  10. #10
    So there's no way to make the code unreadable by humans eyes?
    Something like
    Sub Test()
    XGXGX Chr(x) Chr(=) 1 WX 12 BBKBKQF 
    (I don't remember the ASCII code for x and =)
    instead of
    For x=1 to 12 Then
    If the user of the workbook is not good enough with VBA
    he will not spend time to try undertsanding the code

    It is not possible to do a Function CASCII() (a XL4Macro)
    used for have the ascii code of all characters?

    And then coding the VBA Code with replacing
    all the characters by their ascii code?

  11. #11
    VBAX Regular
    Joined
    May 2004
    Location
    Sydney, Australia
    Posts
    36
    Location
    Hi,

    As has been mentioned several times, this idea is not practical. You would need an un-encrypted procedure that you would use to encrypt/decrypt the rest of your code. Anyone with a little bit of VBA knowledge would easily be able to work out how to decrypt your project. Even if you could get your idea to work it there are so many potential problems that no-one in their right mind would bother with this.

    To summarise (what seems to have been mentioned several times):-

    Either:-

    1) password protect your VBA project. This is the method that the rest of us use to protect our standard Excel files. The password hackers aren't free (at least I've never seen one that's free) and the majority of people on this planet won't try and rip you off.

    If a VBA project password is not enough then:-

    2) create a COM add-in using VB6, VC++, Office Developer, etc.

    Regards,
    Daniel

  12. #12
    VBAX Mentor XL-Dennis's Avatar
    Joined
    May 2004
    Location
    ?stersund, Sweden
    Posts
    499
    Location
    Hi guys

    Let's face it:

    #1 If we want to keep a a secret secret then don't user any computer at all.

    #2 Over 95 % of all Excel-users are not aware of the VB-editor and hardly understand
    what an xla-file is about. Those that would like to decompile / reverse engineering
    will find their ways anyway.

    #3 Most free/ commercial add-ins rely on common code, i e wellknown code with a
    personal twist on it.

    #4 Protecting the VBA-project prevent us from updating modules later. If we ship 500 copies of a tool within a company and we need to update it then the only way to update it will be to replace it...

    #5 Selling a commercial add-in should be based on:
    No shareware-version available and offer some kind of money-guarantee.

    Finally, put the hours to get a reliable and stable solution instead and worry less about this kind of issues

    Kind regards,
    Dennis
    Kind regards,
    Dennis

    ExcelKB | .NET & Excel | 2nd edition PED


  13. #13
    I work with Office 2K Small Business Edition
    My employer hasn't got VB6, VC++, Office Developer.
    Is there any freewares wich can replace these softwares:
    VB6, VC++, Office Developer?
    Where on the net can I find sites about COM and compiling VBA project
    I search in Google and I don't find tips about this.

    Thank you.

    (and apologises for my english)

  14. #14
    VBAX Mentor XL-Dennis's Avatar
    Joined
    May 2004
    Location
    ?stersund, Sweden
    Posts
    499
    Location
    Is there any freewares wich can replace these softwares:
    No

    Where on the net can I find sites about COM and compiling VBA project
    You find several KB-articles here:
    http://www.excelkb.com/article.aspx?id=10008

    But again - Consider my previous post.
    Kind regards,
    Dennis

    ExcelKB | .NET & Excel | 2nd edition PED


  15. #15
    BoardCoder
    Licensed Coder VBAX Expert mark007's Avatar
    Joined
    May 2004
    Location
    Leeds, UK
    Posts
    622
    Location
    Ypu can get VB6 very cheaply on ebay these days - Visual Studio 6 in fact too.
    "Computers are useless. They can only give you answers." - Pablo Picasso
    Mark Rowlinson FIA | The Code Net

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •