BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

How to verify a file is not opened in EXCEL

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (Native API)
View previous topic :: View next topic  
Author Message
Tom Woodrow
Guest





PostPosted: Sat Aug 06, 2005 6:00 am    Post subject: How to verify a file is not opened in EXCEL Reply with quote



Hope that this is the correct group.

I load CSV files into TStringGrid (or TAdvStringGrid). This works great
unless the CSV file is already opened in EXCEL. If this happens I get
error that I can't seem to trap with try/catch.

What is the best way to verify that a CSV file is NOT already opened in
EXCEL before attempting to open with string grid?

Thanks
Tom Woodrow
Back to top
Vladimir Stefanovic
Guest





PostPosted: Sat Aug 06, 2005 6:57 am    Post subject: Re: How to verify a file is not opened in EXCEL Reply with quote



I'm not sure how to check if it's opened by EXCEL
but I know how to check if it is opened by some
other program.

Look at:
http://tinyurl.com/75nlq

There is a routine IsFileOccupied(). Also this routine
must be executed after checking if file exists, etc...


--
Best regards,
Vladimir Stefanovic
"Tom Woodrow" <tomwoodrow (AT) comcast (DOT) net> wrote

Quote:
Hope that this is the correct group.

I load CSV files into TStringGrid (or TAdvStringGrid). This works great
unless the CSV file is already opened in EXCEL. If this happens I get
error that I can't seem to trap with try/catch.

What is the best way to verify that a CSV file is NOT already opened in
EXCEL before attempting to open with string grid?

Thanks
Tom Woodrow



Back to top
Tom Woodrow
Guest





PostPosted: Sat Aug 06, 2005 5:27 pm    Post subject: Re: How to verify a file is not opened in EXCEL Reply with quote



Vladimir,

Thanks for the suggestions. First I use FileExists to verify the file
than use the IfFileOccupied routine from the URL you sent me. I opened a
file with EXCEL and then tested it with IsFileOccupied (below) and get
the EFOpenError exception. It works ok and returns false if the file is
not opened. For some rason the try/catch mechanism is not working here.

Any suggestions?

Thanks
Tom Woodrow


bool IsFileOccupied( const char* s )
{
try
{
TFileStream *tStream = new TFileStream( AnsiString( s ),

fmOpenRead|fmShareExclusive );
delete tStream;
return( false );
}
catch ( const Exception& )
{
return( true );
}

}


Vladimir Stefanovic wrote:
Quote:
I'm not sure how to check if it's opened by EXCEL
but I know how to check if it is opened by some
other program.

Look at:
http://tinyurl.com/75nlq

There is a routine IsFileOccupied(). Also this routine
must be executed after checking if file exists, etc...



Back to top
Vladimir Stefanovic
Guest





PostPosted: Sat Aug 06, 2005 5:53 pm    Post subject: Re: How to verify a file is not opened in EXCEL Reply with quote

Quote:
[...] I opened a file with EXCEL and then tested it with
IsFileOccupied (below) and get the EFOpenError
exception. It works ok and returns false if the file is not opened. For
some rason the try/catch mechanism is
not working here.


It works fine for me. One reason why you can get the
exception is when you start the program from IDE!

Try to execute you program from explorer.



--
Best regards,
Vladimir Stefanovic






Back to top
Tom Woodrow
Guest





PostPosted: Sat Aug 06, 2005 6:15 pm    Post subject: Re: How to verify a file is not opened in EXCEL Reply with quote

Vladimir,

OK, from the IDE it works properly. Is there any way to get it to work
within the IDE also.

Thanks
Tom Woodrow

Vladimir Stefanovic wrote:

Quote:
[...] I opened a file with EXCEL and then tested it with
IsFileOccupied (below) and get the EFOpenError
exception. It works ok and returns false if the file is not opened. For
some rason the try/catch mechanism is
not working here.



It works fine for me. One reason why you can get the
exception is when you start the program from IDE!

Try to execute you program from explorer.




Back to top
Heinrich Wolf
Guest





PostPosted: Sat Aug 06, 2005 6:41 pm    Post subject: Re: How to verify a file is not opened in EXCEL Reply with quote


"Tom Woodrow" <tomwoodrow (AT) comcast (DOT) net> schrieb im Newsbeitrag
news:42f4fe39$1 (AT) newsgroups (DOT) borland.com...
Quote:
Vladimir,

OK, from the IDE it works properly. Is there any way to get it to work
within the IDE also.

Thanks
Tom Woodrow

Hi

modify the exception handling of the IDE.
Menu: Tools - Debugger-Options
There are 2 Tabs with many settings.

Regards
Heiner



Back to top
Vladimir Stefanovic
Guest





PostPosted: Sat Aug 06, 2005 6:46 pm    Post subject: Re: How to verify a file is not opened in EXCEL Reply with quote

Quote:
OK, from the IDE it works properly. Is there any way
to get it to work within the IDE also.

Yes, there is a way, but I'm not sure about the steps.

Probably:

Tools / Debugger Options / [maybe] OS Excptions

.... and try checking/unchecking to find out how to supress
exceptions.




--
Best regards,
Vladimir Stefanovic



Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (Native API) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.