Testing for an open file

  • Thread starter Thread starter Nigel
  • Start date Start date
N

Nigel

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

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

Back
Top