Prev: Excel how to tell if workbook is already open BEFORE you try to open it.
Next: validate wmf files?
From: Harlan Messinger on 3 May 2010 17:32 Jeff Johnson wrote: > "hdjim" <hdjim69(a)yahoo.com> wrote in message > news:121fe4a0-138e-497f-b6b7-32b4b3f9ef7a(a)o14g2000yqb.googlegroups.com... > >> I've been looking all over the net trying to find C# code to determine >> if a workbook is open before you try to open it so you can alert the >> user to close it before you update it. >> >> There must be a way. Please help. > > The easiest way is to try to open the file for writing and see if the > operation fails (i.e., trap the exception). When you successfully open a file for writing, doesn't that delete the existing contents?
From: Harlan Messinger on 3 May 2010 19:16 Jeff Johnson wrote: > "Harlan Messinger" <hmessinger.removethis(a)comcast.net> wrote in message > news:848tnmF251U1(a)mid.individual.net... > >>>> I've been looking all over the net trying to find C# code to determine >>>> if a workbook is open before you try to open it so you can alert the >>>> user to close it before you update it. >>>> >>>> There must be a way. Please help. >>> The easiest way is to try to open the file for writing and see if the >>> operation fails (i.e., trap the exception). >> When you successfully open a file for writing, doesn't that delete the >> existing contents? > > No, depending on the mode you use to open. Think about it: how could you > ever append to a file if that were the case? OK, fine, for appending. :-) The terminology is tricky--sometimes when they say "write" they mean, as opposed to "append". > > I guess you could also try to open for read with a ShareDenyRead lock. > >
|
Pages: 1 Prev: Excel how to tell if workbook is already open BEFORE you try to open it. Next: validate wmf files? |