ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Testing for an open file (https://www.excelbanter.com/excel-programming/334079-testing-open-file.html)

Nigel

Testing for an open file
 
I have an application that appends a log to a CSV file as each instance of
the application ends. The CSV is used by others on an infrequent basis to
check on the log. The CSV file sits on a shared server/directory for this
purpose.

Usually the coincidence of the application ending and the CSV being open is
very rare (never happended in 18 months -so far!). The problem arises when
the CSV is left open as recently happended in this case the application
failed as it couild not write to the CSV file. My application needs to
detect this, issue a warning and wait for the CSV to be released or store
the log locally and append it next time the application is run.

How can I detect if a CSV is open and therefore not available to be updated?
Also is it possible to identify the user who has the file open, in a similar
way that Excel warns if an Excel Workbook is open?


--
Cheers
Nigel





William Benson[_2_]

Testing for an open file
 
Try this:

Open it for APPEND, append your username to the bottom, close it

Open it, go to EOF, look for your username. If it is there, you own the
file.

If it is not there, consider yourself locked out.

Remember to remove your username!

Bill

"Nigel" wrote in message
...
I have an application that appends a log to a CSV file as each instance of
the application ends. The CSV is used by others on an infrequent basis to
check on the log. The CSV file sits on a shared server/directory for this
purpose.

Usually the coincidence of the application ending and the CSV being open
is
very rare (never happended in 18 months -so far!). The problem arises
when
the CSV is left open as recently happended in this case the application
failed as it couild not write to the CSV file. My application needs to
detect this, issue a warning and wait for the CSV to be released or store
the log locally and append it next time the application is run.

How can I detect if a CSV is open and therefore not available to be
updated?
Also is it possible to identify the user who has the file open, in a
similar
way that Excel warns if an Excel Workbook is open?


--
Cheers
Nigel







Tom Ogilvy

Testing for an open file
 
Here is what Microsoft recommends:

http://support.microsoft.com?kbid=138621
XL: Macro Code to Check Whether a File Is Already Open

http://support.microsoft.com?kbid=291295
XL2002: Macro Code to Check Whether a File Is Already Open

http://support.microsoft.com?kbid=213383
XL2000: Macro Code to Check Whether a File Is Already Open

http://support.microsoft.com?kbid=184982
WD97: VBA Function to Check If File or Document Is Open

I haven't seen anything on detecting who has the file open, but that might
be possible using the Windows API or related.

--
Regards,
Tom Ogilvy

"Nigel" wrote in message
...
I have an application that appends a log to a CSV file as each instance of
the application ends. The CSV is used by others on an infrequent basis to
check on the log. The CSV file sits on a shared server/directory for this
purpose.

Usually the coincidence of the application ending and the CSV being open

is
very rare (never happended in 18 months -so far!). The problem arises

when
the CSV is left open as recently happended in this case the application
failed as it couild not write to the CSV file. My application needs to
detect this, issue a warning and wait for the CSV to be released or store
the log locally and append it next time the application is run.

How can I detect if a CSV is open and therefore not available to be

updated?
Also is it possible to identify the user who has the file open, in a

similar
way that Excel warns if an Excel Workbook is open?


--
Cheers
Nigel







Nigel

Testing for an open file
 
Thanks for the information - very useful

--
Cheers
Nigel



"Tom Ogilvy" wrote in message
...
Here is what Microsoft recommends:

http://support.microsoft.com?kbid=138621
XL: Macro Code to Check Whether a File Is Already Open

http://support.microsoft.com?kbid=291295
XL2002: Macro Code to Check Whether a File Is Already Open

http://support.microsoft.com?kbid=213383
XL2000: Macro Code to Check Whether a File Is Already Open

http://support.microsoft.com?kbid=184982
WD97: VBA Function to Check If File or Document Is Open

I haven't seen anything on detecting who has the file open, but that might
be possible using the Windows API or related.

--
Regards,
Tom Ogilvy

"Nigel" wrote in message
...
I have an application that appends a log to a CSV file as each instance

of
the application ends. The CSV is used by others on an infrequent basis

to
check on the log. The CSV file sits on a shared server/directory for

this
purpose.

Usually the coincidence of the application ending and the CSV being open

is
very rare (never happended in 18 months -so far!). The problem arises

when
the CSV is left open as recently happended in this case the application
failed as it couild not write to the CSV file. My application needs to
detect this, issue a warning and wait for the CSV to be released or

store
the log locally and append it next time the application is run.

How can I detect if a CSV is open and therefore not available to be

updated?
Also is it possible to identify the user who has the file open, in a

similar
way that Excel warns if an Excel Workbook is open?


--
Cheers
Nigel










All times are GMT +1. The time now is 12:03 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com