vba 如何防止用户访问VBA?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1129564/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 10:36:25  来源:igfitidea点击:

How to prevent users from accessing VBA?

vbapassword-protection

提问by raghvendra

we have a COM add-in that we use in MS Office application like Word and Excel. That COM add-in has exposed few APIs to use, which we use for customization.

我们有一个 COM 加载项,我们在 Word 和 Excel 等 MS Office 应用程序中使用。该 COM 加载项公开了很少的 API 可供使用,我们将其用于自定义。

Problem is - Any user can access the APIs and that is causing security problems. we dont want that to happen, we want to give access to VBA editor to only few peoples.

问题是 - 任何用户都可以访问 API,这会导致安全问题。我们不希望这种情况发生,我们希望只有少数人可以访问 VBA 编辑器。

Is there any way - to disable VBA editor, without disabling VBA, because we want to use other Macros and Add-ins.

有什么办法 - 禁用 VBA 编辑器,而不禁用 VBA,因为我们想使用其他宏和加载项。

Thanks in advance!

提前致谢!

PS - I tried hiding 'Developer' tab from toolbar but anyone who knows shortcut (ALT-F11), can still use it.

PS - 我尝试从工具栏中隐藏“开发人员”选项卡,但任何知道快捷方式 (ALT-F11) 的人仍然可以使用它。

回答by Oorang

If one of the requirements of the COM Add-In is restricted access, the solution shouldn't be to disable anything than can access it. The answer should be to fix the add-in itself. An easy way to do it would be to define a user group that can use the add-in, and then just make the add-in check to verify the user is a member of that group. That should be simple to implement and simple to maintain.

如果 COM 加载项的要求之一是限制访问,则解决方案不应是禁用任何不能访问的内容。答案应该是修复加载项本身。一个简单的方法是定义一个可以使用加载项的用户组,然后只需进行加载项检查以验证用户是该组的成员。这应该易于实施且易于维护。

回答by SheetJS

The VBA Password Protection does not actually protect you from people reading the file. It's incredibly simple to remove the protection.

VBA 密码保护实际上并不能保护您免受阅读文件的人的侵害。移除保护非常简单。

One alternative is to obfuscate the COM API as well as the VBA (so that, even if people can read the code, it would be difficult to figure out what's going on). Apple has done this in the past (e.g. isYoMamaWearsCombatBootsSupported -- https://github.com/JaviSoto/iOS7-Runtime-Headers/commit/6ccf9c4526992fec0dc414d48e4a3f7446e9822f#L10R61)

一种替代方法是混淆 COM API 和 VBA(这样,即使人们可以阅读代码,也很难弄清楚发生了什么)。Apple 过去曾这样做过(例如 isYoMamaWearsCombatBootsSupported -- https://github.com/JaviSoto/iOS7-Runtime-Headers/commit/6ccf9c4526992fec0dc414d48e4a3f7446e9822f#L10R61

回答by Byron Whitlock

Can't you add a password to view/edit code? then at least they can't see your api and should prevent them from opening the editor.

您不能添加密码来查看/编辑代码吗?那么至少他们看不到你的api,应该阻止他们打开编辑器。

Right click the project in the VBA project window and select 'properties' to add a password to that project in the Protection tab.

右键单击 VBA 项目窗口中的项目,然后选择“属性”以在“保护”选项卡中为该项目添加密码。