vba:如何以只读方式以编程方式打开工作簿?

时间:2022-09-11 16:43:55

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.

有没有办法指定它应该以只读方式打开?我打开的文件有密码,我总是得到一个只能打开的对话框。

2 个解决方案

#1


27  

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)

#2


10  

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)

#1


27  

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)

#2


10  

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)