我被要求更新一些Excel 2003宏,但是VBA项目有密码保护,而且似乎缺乏文档…没人知道密码。

是否有一种方法可以删除或破解VBA项目的密码?


当前回答

删除VBA项目密码的一个简单方法是执行以下操作:

将xlsm文件转换为zip 打开VBAProject.bin文件(我更喜欢使用notepad++ (https://notepad-plus-plus.org/downloads/)) 搜索DPB字段 用DPx替换它 保存文件 将zip文件转换为XLSM 打开excel文件 如果出现消息框,请单击“是” 为VBA项目属性设置新密码 关闭并再次打开该文件 输入新密码取消保护

其他回答

对于Excel 2007,您需要将文件扩展名更改为。zip 在存档中有一个子文件夹xl,在那里你会发现vbaProject.bin。 使用vbaProject.bin执行上面的步骤,然后将其保存回存档中。 修改回您的扩展名和voilà!(意思是遵循上面的步骤)

Colin Pickard has an excellent answer, but there is one 'watch out' with this. There are instances (I haven't figured out the cause yet) where the total length of the "CMG=........GC=...." entry in the file is different from one excel file to the next. In some cases, this entry will be 137 bytes, and in others it will be 143 bytes. The 137 byte length is the odd one, and if this happens when you create your file with the '1234' password, just create another file, and it should jump to the 143 byte length.

如果您尝试将错误的字节数粘贴到文件中,当您尝试用Excel打开该文件时,您将丢失VBA项目。

EDIT

这对Excel 2007/2010文件无效。标准的。xlsx文件格式实际上是一个。zip文件,包含许多子文件夹,其中格式、布局、内容等存储为xml数据。对于未受保护的Excel 2007文件,只需将.xlsx扩展名更改为.zip,然后打开zip文件并查看所有xml数据。这很简单。

但是,当您对Excel 2007文件进行密码保护时,整个.zip (.xlsx)文件实际上是使用RSA加密进行加密的。不再可以将扩展名更改为.zip并浏览文件内容。

Tom -我最初犯了一个学生错误,因为我没有注意字节大小,而是从“CMG”设置复制粘贴到后续条目。这两个文件之间有两种不同的文本大小,但是,正如Stewbob警告的那样,我丢失了VBA项目。

使用HxD,有一个计数器跟踪您选择了多少文件。从CMG开始复制,直到计数器读取8F(十六进制为143),同样地,当粘贴到锁定文件时-我最终在粘贴的末尾使用了两倍的“…”,这看起来有点奇怪,感觉几乎不自然,但它起作用了。

我不知道这是否重要,但在excel中重新打开文件之前,我确保关闭了十六进制编辑器和excel。然后我必须通过菜单打开VB编辑器,进入VBProject属性,并输入'new'密码来解锁代码。

我希望这能有所帮助。

对于.xlsm或.dotm文件类型,您需要以稍微不同的方式进行操作。

Change the extension of the .xlsm file to .zip. Open the .zip file (with WinZip or WinRar etc) and go to the xl folder. Extract the vbaProject.bin file and open it in a Hex Editor (I use HxD, its completely free and lightweight.) Search for DPB and replace with DPx and save the file. Replace the old vbaProject.bin file with this new on in the zipped file. Change the file extension back to .xlsm. Open workbook skip through the warning messages. Open up Visual Basic inside Excel. Go to Tools > VBAProject Properties > Protection Tab. Put in a new password and save the .xlsm file. Close and re open and your new password will work.

删除VBA项目密码的一个简单方法是执行以下操作:

将xlsm文件转换为zip 打开VBAProject.bin文件(我更喜欢使用notepad++ (https://notepad-plus-plus.org/downloads/)) 搜索DPB字段 用DPx替换它 保存文件 将zip文件转换为XLSM 打开excel文件 如果出现消息框,请单击“是” 为VBA项目属性设置新密码 关闭并再次打开该文件 输入新密码取消保护