Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I open workbook programmatically as read-only?

Tags:

excel

vba

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.

like image 890
Alex Gordon Avatar asked Aug 02 '10 16:08

Alex Gordon


1 Answers

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)
like image 81
LittleBobbyTables - Au Revoir Avatar answered Oct 26 '22 06:10

LittleBobbyTables - Au Revoir