A VBA encryption method using COM interactive mechanism, suitable for most VBA code encryption

Source: Internet
Author: User

Original source: http://www.cnblogs.com/Charltsing/p/EncryptVBACode.html

VBA code encryption is a commonplace issue, and since my VBA dumper was released, any encryption at the office level has lost its meaning. So, many people began to move to the VB package or upgrade to Vsto,delphi and other languages. However, for the vast majority of Vbaer, the problem of re-learning a language is far more than the benefits of developing VBA programs. So, is there a way to encrypt VBA code out of office without changing the VBA code?

Given that Office supports COM plug-ins, is it possible to complete the dynamic decryption of VBA code files via an add-in, real-time insertion, real-time operation, and the removal of this series of protection code actions? This way, the VBA code does not exist with the Office file, and there is sufficient means to encrypt the VBA plaintext code.

I developed the VBA smart typesetting plugin smart indenter for VBE last year, then I use this plugin to complete the above functions.

The way to use it is simple:

Refer to the following code to call the encrypted VBA code file, support sub and function, the default support five parameters, support indeterminate parameters.

' redaction function test public Sub sampleencryptvba ()    Dim oadd As Object, obj as Variant    Dim modulename$, vbafilefullpath$, RET    ' establish VBA dynamic call on    Error Resume Next    Set oadd = GetObject (, "Smartindentervbe.connect")    If Err <> 0 Then        MsgBox "Please press ALT-F11 to enter the VBE once before running the macro!" "        End    end If    Set obj = oadd.instance call    obj." Setexcelapp (application)    ' code file to run    Vbafilefullpath = Thisworkbook.path & Application.PathSeparator & "Encryptedemo.txt"    ' runvbafunction is run VBA function, parameters: file name, document key, file code, function name, function parameter 1, function parameter 2, function parameter 3 ... (more than five use indefinite parameters)    ret = obj. Runvbafunction (Vbafilefullpath, "abc", True, "Returnrangevalue", Range ("A1"))    MsgBox retend Sub

Function Description:
1, this function is only a VBA encryption idea, for everyone reference. VBA code is written correctly to ensure that the code cannot be interrupted because of various error conditions (the simplest option is to add On Error Resume Next)
2. It is not recommended that all VBA code be dynamically generated and recommended for use in some core functions.
3. This feature is not always cracked, but it has the advantage of moving the encryption layer of VBA code from office to outside, which provides a lot of possibilities for protecting your code.

Demo Description:

In the following demo, you can see that the VBA process is running, the VBA code is dynamically generated by the plug-in into Excel, and then run through the Application.Run command. The advantage of this encryption is that there is no need to change the VBA code, and of course there is no need to learn any new language. suitable for children's shoes that focus on the development of VBA applications.

The demo file is downloaded and the smart indenter for VBE plugin is not installed, please download and install it first.

Technical Exchange Please contact qq:564955427

A VBA encryption method using COM interactive mechanism, suitable for most VBA code encryption

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.