Excel VBA 2007 以只读模式保存工作簿

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

Excel VBA 2007 Save workbook in read-only mode

excelvba

提问by Wes

Lets say a workbook is writeable, but is opened for read-only (through a read-only shortcut where the /rswitch is used), and it has not been modified since someone has had it opened for read-only. How to allow them to save changes from VBA for Excel 2007 without re-opening?

假设工作簿是可写的,但以只读方式打开(通过/r使用开关的只读快捷方式),并且自从有人将其打开为只读后,它就没有被修改。如何允许他们在不重新打开的情况下保存来自 VBA for Excel 2007 的更改?

I seemed to be able to do it with 2003 but not with 2007. In 2003 this seemed to work:

我似乎能够在 2003 年做到这一点,但在 2007 年却不行。在 2003 年,这似乎奏效了:

ActiveWorkbook.ChangeFileAccess (Excel.XlFileAccess.xlReadWrite)
ActiveWorkbook.Save
ActiveWorkbook.ChangeFileAccess (Excel.XlFileAccess.xlReadOnly)

But in 2007 no longer. Thanks

但在2007年不再。谢谢

回答by Jean-Fran?ois Corbett

How about ActiveWorkbook.SaveAsto some temp filename, then Killthe old file, then rename the temp file to the old path using Name?

如何ActiveWorkbook.SaveAs使用一些临时文件名,然后Kill是旧文件,然后使用 将临时文件重命名为旧路径Name