简体   繁体   English

C#运行具有密码的excel宏

[英]C# run excel macro that has a password

I have an excel workbook that contains a macro which contains a password. 我有一个Excel工作簿,其中包含一个包含密码的宏。 I have a C# app that calls this excel macro (not my design). 我有一个调用此excel宏的C#应用​​(不是我的设计)。 I was wondering if there was a away to password protect the excel macro so people cannot see the password but can still be called by my C# app. 我想知道是否可以通过密码保护excel宏,以便人们看不到密码,但仍可以由我的C#应用​​程序调用。

The password has to remain in the workbook so I cannot just move it to my C# app, again this is not my design. 密码必须保留在工作簿中,所以我不能只将密码移到我的C#应用​​程序中,这又不是我的设计。

Password-protecting a macro does NOT prevent it from being executed , only viewed and edited . 密码保护宏不会阻止其执行 ,只能对其进行查看和编辑

Just go to the Module properties in the VBA editor, click the "protection" tab and add a password. 只需在VBA编辑器中转到“模块”属性,单击“保护”选项卡并添加密码即可。

Note that string constants are not encrypted in the source file, so you may want to obfuscate the password if it's a human-readable password so it's not easily recognizable by looking at the excel file in a text editor. 请注意,字符串常量未在源文件中加密,因此,如果该密码是人类可读的密码,则可能需要对其进行混淆处理,因此通过在文本编辑器中查看excel文件不容易识别该密码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM