11

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.

peterh
  • 11,875
  • 18
  • 85
  • 108
Alex Gordon
  • 57,446
  • 287
  • 670
  • 1,062

2 Answers2

42

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)
Community
  • 1
  • 1
LittleBobbyTables - Au Revoir
  • 32,008
  • 25
  • 109
  • 114
  • 1
    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'. – CAD.Dev Mar 28 '16 at 02:08
15

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)
buckbova
  • 1,213
  • 6
  • 11