我想自动写入一个Excel VBA宏输入密码的用户。 通过这种方式,用户不需要输入每次双击文件时手动输入密码。 这可能吗? 如果是这样,我怎么能这样做呢?
Answer 1:
As mentioned in my comment, the functionality that you seek, in my opinion cannot be done. Let me explain it.
To auto run a VBA code in an Excel file you need to place the code either in the Workbook_Open()
in the ThisWorkbook
code area or in Auto_Open()
in a module.
Now these two Subs execute only after the password has been entered in a password protected file i.e after the workbook has opened. So there is no way this can be run before the password is fed to the password dialog box or before the Workbook is opened.
I am sure your boss is a sensible guy and will understand if you can explain it nicely to him :)
You might also want to see this link which explains more in details about running the macro automatically.
Topic: Running a macro when Excel starts
Link : http://office.microsoft.com/en-us/excel-help/running-a-macro-when-excel-starts-HA001034628.aspx
Quote from the above link
If you want to automatically perform certain actions whenever you start Microsoft Excel, you can record or write a macro that will run whenever you open a workbook. There are two ways to do this:
Record a macro and save it using the name Auto_Open. Write the macro as a Microsoft Visual Basic® for Applications (VBA) procedure for the Open event of a workbook.
Answer 2:
没有命令行参数的密码来传递。 但是你可以做的是有一个“开门红”的电子表格,需要一个电子数据表名和密码作为参数,并使用VBA打开密码保护的电子表格。
看看他的链接:
https://superuser.com/questions/438842/excel-workbook-desktop-shortcut-with-auto-password
那只能说明你如何得到命令行参数 - 一旦你有那些你可以使用:
Workbooks.Open "filename", , , , "Password"
Answer 3:
@iceagle,我没有足够的声誉上@(亚洲时报Siddharth劳斯),以“评”,但很遗憾的意见并说这是没有意义的/无用的回答/无法做到的。
举例来说,如果你有一整套要改变过人之处,但都被密码保护。 如果现在你通过你再次输入密码每次循环运行它们(似乎愚蠢时,你有超过1000个文件,不是吗?)一个更好的选择:VBS编码,这在有密码的宏观和为此可以改变一切该编码的文件! 提供此密码的用户,现在你仍然有1000页编码的文件只有你不必每次输入。
现在的答案,如果人们归到这,是正确地@DJ给出。 你可以把密码到工作簿揭幕战这样的命令行:
Set wb = Workbooks.Open(Filename:="myfile.xls", Password:="password")
我希望遇到这样的人不采取接受的答案给出,但进一步看。
亲切的问候,彼得