Problem opening Excel files in edit mode

Hi experts,
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?

Thanks,
     Michael
gem56Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
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.

mvidasCommented:
Hi Michael,

I've encountered similar things in the past, sometimes I find it helps to not use Named arguments, like:
 Set mExcelWorkbook = ExcelApp.Workbooks.Open(sFileName, , True)

If need be, you could even suppress the warning messages while opening (in case someone has it open, it will probably still prompt you):
 ExcelApp.DisplayAlerts = False
 Set mExcelWorkbook = ExcelApp.Workbooks.Open(sFileName, , True)
 ExcelApp.DisplayAlerts = True

Matt

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
gem56Author Commented:
Hi mvidas,
Sorry for not getting back earlier. I tried your suggestion as soon as you made it but it didn't seem to make any difference and I got carried away with remaining issues and development and simply forgot to respond, again sorry.

As I said, I still get the same thing happening but thanks for pointing out that in some cases not using Named arguments helps so on closing I'll give you some points, unless you have any further suggestion.

/Michael
mvidasCommented:
The delay isn't a problem, Michael, I was actually not available myself due to a few medical issues so I wouldnt have been able to get back to you sooner anyways (unless it was the morning you asked the question).
I have noticed that sometimes these read only / edit mode messages don't follow normal logic when you're accessing a file on a network/shared drive.  
Unfortunately I don't really know a good workaround, but you may want to post a 20-point question at http://www.experts-exchange.com/Applications/MS_Office/Excel/ as a 'pointer' to this question, get some fresh eyes looking at this question.  Add something in there to only comment in this (original) question, then when this is resolved you can just delete your pointer question.  Might be worth a try!
Matt
gem56Author Commented:
Thanks mvidas for your suggestion, I'll do that.
/Michael

gem56Author Commented:
Hi mvidas,
I gave you the points and only Average rating because it didn't resolve my problem however I did learn something from your response that I didn't know previously.
/Michael
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 Classic

From novice to tech pro — start learning today.