I have a problem opening an Excel file in edit/non-edit mode, using the following VB code statements:
1) Set mExcelWorkbook = excelApp.Workbooks.Open(FileName:=sFileName, ReadOnly:=True)
2) Set mExcelWorkbook = excelApp.Workbooks.Open(FileName:=sFileName)
By that I mean if statement 1) is executed and I try to open the (sFileName) using Excel, I get a message saying that file is locked for editing. Why?
If however I first open the file using Excel and then run my application, executing statement 1), I don't get any warnings. To me that suggests that VB doesn't see any problems opening (an already open) file because it is not trying to edit the file so all is OK.
If I use statement 2 and repeat the same exercise, I get the same result; which doesn't make sense to me. If the file is already open by Excel (in edit mode) then I should get an error executing statement2, shouldn't I?
Can someone tell me what should my statement be to open a file in ReadOnly mode so that I don't get a warning message in Excel application?