12

This is how I can open an excel file in vbA:

Workbooks.Open(file-path)

is there a way to specify that it should be open as read-only? The files I am opening have a password on them, and I always get the dialog that it can only be open as read only.

2 Answers 2

44

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)
Sign up to request clarification or add additional context in comments.

1 Comment

It is helpful to know that you should encapsulate the arguments in a parenthesis if you intend on storing the opened workbook in a variable using 'Set'.
16

Check out the language reference:

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 Comment

Better response as it also makes it clear that password can be used on open.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.