保护 Excel VBA 代码的最佳方法?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16757119/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Best way to protect Excel VBA code?
提问by Chronix3
I've put together a simple Excel database that performs a few macro functions and I need to distribute this database to a few people - but they cannot see how the macro function actually works (stupid rules I have to follow!). What is the best way to achieve this?
我已经建立了一个简单的 Excel 数据库,它执行一些宏函数,我需要将这个数据库分发给一些人 - 但他们看不到宏函数的实际工作原理(我必须遵循愚蠢的规则!)。实现这一目标的最佳方法是什么?
I've done a bit of research and I found two ways:
我做了一些研究,发现了两种方法:
Password protect the VBA project; but this is apparently very easy to break using readily available tools online (it would be in the best interest to the people I'm sending this to find out how the macros and functions work; so I'm almost 100% sure they will try to get into it.. hence a password protection seems inadequate.
Move to a fully compiled language like C++; my skills are very limited to VBA on Excel and Access so this being the ideal solution; isn't a solution for me :(
密码保护 VBA 项目;但这显然很容易使用现成的在线工具来破解(这对我发送此邮件的人最感兴趣,以了解宏和函数的工作原理;所以我几乎 100% 确定他们会尝试进入它......因此密码保护似乎不够。
转向完全编译的语言,如 C++;我的技能仅限于 Excel 和 Access 上的 VBA,因此这是理想的解决方案;对我来说不是解决方案:(
Are there any other ways? I thought of having a 'master excel document' with all the macros in that and then send 'children' databases to the end users and have the 'children' databases connect to the 'master' - is something like this possible? By hosting the master online or even sending the end users the master but making it completely inaccessible unless accessed by the 'children' databases?
还有其他方法吗?我想拥有一个包含所有宏的“主 excel 文档”,然后将“子”数据库发送给最终用户,并将“子”数据库连接到“主”——这样的事情可能吗?通过在线托管主服务器,甚至将主服务器发送给最终用户,但除非“儿童”数据库访问,否则完全无法访问?
采纳答案by Santosh
You can create Automation Add In.
您可以创建自动化插件。
An Automation Add In provides several advantages
自动化插件提供了几个优点
Execution Speed: An Automation Add In written in VB6is compiled to native machine code which runs much faster than the interpreted VBA languange.
Security: Unlike an XLA add in, you never distribute the source code to the end users. If your code has proprietary information or intellectual property value, that remains safely protected on your own computer. It is never distributed to the user. Your code can never be compromised.
执行速度:用 VB6 编写的自动化插件被编译为本机代码,其运行速度比解释的 VBA 语言快得多。
安全性:与 XLA 插件不同,您永远不会将源代码分发给最终用户。如果您的代码具有专有信息或知识产权价值,则在您自己的计算机上仍然受到安全保护。它永远不会分发给用户。您的代码永远不会受到损害。
回答by NikoDeem
There aren't too many ways to protect your Excel VBA code reliably.
没有太多方法可以可靠地保护 Excel VBA 代码。
You can try to use passwords or VBA obfuscators, but all of that protection is limited. Passwords are easy to break, and obfuscated VBA code can still be traced back and recovered.
您可以尝试使用密码或 VBA 混淆器,但所有这些保护都是有限的。密码很容易破解,混淆后的 VBA 代码仍然可以追溯和恢复。
The other answer to this question mentions using VB6, but that limits your code to 32bit Excel. Also VB6 can be decompiled by VB decompiler.
这个问题的另一个答案提到使用 VB6,但这将您的代码限制为 32 位 Excel。VB6 也可以通过 VB 反编译器进行反编译。
Converting your code to a compiled language is indeed the best way to protect your VBA code, but be warned that in this case not all code is created equal.
将代码转换为编译语言确实是保护 VBA 代码的最佳方式,但请注意,在这种情况下,并非所有代码都是平等的。
Converting your code to VBA.NET is a flawed solution because the compiled code of .NET assembly can be converted back into the original source code.
将代码转换为 VBA.NET 是一个有缺陷的解决方案,因为 .NET 程序集的编译代码可以转换回原始源代码。
Converting your VBA code to C or C++ is the most effective form of protection, but this takes a lot of experience and effort since C/C++ and VBA are very different languages.
将 VBA 代码转换为 C 或 C++ 是最有效的保护形式,但这需要大量的经验和努力,因为 C/C++ 和 VBA 是非常不同的语言。
I would suggest you have a look at a tool called VBA Compiler for Excel (https://vbacompiler.com/how-to-compile/). It compiles your Excel VBA code into a DLL file with a click. You do not need any knowledge of C or C++ languages to use it.
我建议您查看一个名为 VBA Compiler for Excel ( https://vbacompiler.com/how-to-compile/) 的工具。只需单击一下,它就会将您的 Excel VBA 代码编译成一个 DLL 文件。您不需要任何 C 或 C++ 语言知识即可使用它。