How to open excel files in read only with ClosedXML in

I'm using below code to access and read my excel file but it gives an error if my excel file open.

So how can i use it read only ? Any help would be grateful.

        Dim workbook As New ClosedXML.Excel.XLWorkbook("C:\Users\USER\Desktop\ChassisModel\genChassis.xlsx")
        Dim rowsNode = workbook.Worksheet("NodeList").RangeUsed().RowsUsed().Skip(1)

Open in new window

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Chinmay PatelChief Technology NinjaCommented:
Hi Hakan,

Please try:

Dim workbook As New ClosedXML.Excel.XLWorkbook("C:\Users\USER\Desktop\ChassisModel\genChassis.xlsx", False)
Dim rowsNode = workbook.Worksheet("NodeList").RangeUsed().RowsUsed().Skip(1)

Open in new window

HakanAuthor Commented:
Sorry Chimnay, I was thought it was solution but this False is related to another thing i think. Problem continues.
HakanAuthor Commented:
I found a solution on net for C# and converted it to my code and it works now. Thank you.    

   Dim fileStream As New FileStream(fileExcel, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)
        Dim workbook As New ClosedXML.Excel.XLWorkbook(fileStream)

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Chinmay PatelChief Technology NinjaCommented:
No worries. I am glad that you found a solution on your own and on top of that you shared it here with the community. I have rarely seen people doing it. Keep up the good work.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.