Able to open same excel workbook at the same time !

A

ann

Hi Everyone !
I m a newbie to excel programming but I noticed a bug (??) while
working with excel & VS.NET. I m able to open an excel workbook in 2
different instances of my application & I cant find a way to prevent
this from happening. As a result, 2 different users can , effectively
work on the same workbook, on a same worksheet & over-ride each other's
saves !!
Pls help if anyone has faced a similar problem & if there is anyway to
prevent this !

Thanks in advance
~Ann
 
B

Bob Phillips

Surely, one of them will open it as read-only, thereby not being able to
write it back. You can test for this property.

--
HTH

Bob Phillips

(remove xxx from email address if mailing direct)
 
A

ann

That is the problem neither Excel or XP (the OS I am using it with)
detects this & allows me to open & work on the same workbook at the
same time. !

Is there someway to check in C# if a file is already open ?
I found a lot of code using VB that allows a file to be locked while
opening and thereby detecting another open attempt on an already open
file.
Cannot find anything similar in C#

Thanks
 
B

Bob Phillips

Don't know C#, but as I said, if you open it and then check it's ReadOnly,
which is

ActiveWorkbook.ReadOnly

in VBA, and act accordingly.

--
HTH

Bob Phillips

(remove xxx from email address if mailing direct)
 
A

ann

Thanks for your prompt replies Bob.
I realised that the solution lies in using the VBA. I was using Interop
till now.
I was able to check if the file is already open using VBA.FileOpen
method.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top