vba:如何以只读方式以编程方式打开工作簿?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3389543/
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
vba: how do i open workbook programmatically as read-only?
提问by l--''''''---------''''''''''''
this is how i can open an excel file in vbA:
这是我如何在 vbA 中打开一个 excel 文件:
Workbooks.Open(file-path)
is there a way to specify that it should be open as read-only? the files im opening have a password on them and i always get the dialog that it can only be open as read only.
有没有办法指定它应该以只读方式打开?我打开的文件上有密码,我总是收到对话框,说它只能以只读方式打开。
回答by LittleBobbyTables - Au Revtheitroad
Does this work?
这行得通吗?
Workbooks.Open Filename:=filepath, ReadOnly:=True
Or, as pointed out in a comment, to keep a reference to the opened workbook:
或者,正如评论中指出的那样,保留对打开的工作簿的引用:
Dim book As Workbook
Set book = Workbooks.Open(Filename:=filepath, ReadOnly:=True)
回答by buckbova
Check out the language reference:
查看语言参考:
http://msdn.microsoft.com/en-us/library/aa195811(office.11).aspx
http://msdn.microsoft.com/en-us/library/aa195811(office.11).aspx
expression.Open(FileName, UpdateLinks, ReadOnly, Format, Password, WriteResPassword, IgnoreReadOnlyRecommended, Origin, Delimiter, Editable, Notify, Converter, AddToMru, Local, CorruptLoad)

