"SaveAS" Excel中具有密码保护的宏 [英] "SaveAS" macro in excel with password protection
问题描述
我在Excel文件中有此宏:
Hi I have this macro in excel file:
ActiveWorkbook.SaveAs filename:="C:\SAP Imports\Sales Orders\" & Range("A1") & ".xlsm", FileFormat:= _
xlNormal, Password:="", WriteResPassword:="", ReadOnlyRecommended:=False _
, CreateBackup:=False
此宏受密码保护.当我运行此代码时,出现运行时"错误,并且我无法弄清楚我的代码有什么问题.
This macro is password protected. Whenevr I run this I get "run time" error and I am not able to figure out whats wrong with my code.
我应该写密码而不是写".请告知.
Should I write my password instead of writing "". Please advise.
推荐答案
我用相同的东西设置了一个工作簿,当我保护宏并将密码放在显示的行中时,它保存得很好.
I set up a workbook with the same thing and when I protected the macro and placed the password in the lines you showed then it saved just fine.
但是,当我尝试打开另一个工作簿时,这导致了第二个问题.然后,我收到一条错误消息,指出文件格式不正确.我通过删除".xlsm"
并将文件格式更改为fileformat:=52
来更改您的行.最终成功了
This led to a second problem, however, when I tried to open up the other workbook. I then got an error saying that the file was an incorrect format. I changed your line by deleting the ".xlsm"
and changing the fileformat to fileformat:=52
. This ended up making it
ActiveWorkbook.SaveAs filename:="C:\SAP Imports\Sales Orders\" & Range("A1"), FileFormat:=52, Password:="password", WriteResPassword:="password", ReadOnlyRecommended:=False, CreateBackup:=False
当我将其更改为此时,工作簿保存就很好了.当我打开保存的书时,它提示我输入上面输入的密码.
When I changed it to this then the workbook saved just fine. When I opened up the saved book it prompted me for the passwords that were entered above.
这篇关于"SaveAS" Excel中具有密码保护的宏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!