Solved

In Access vba detect whether an excel file is open

Posted on 2011-09-21
3
305 Views
Last Modified: 2012-05-12
I want to read/update information off an excel spreadsheet but don't want to do this while someone has it open. You cannot delete a file when someone has it open so system must record somewhere? - is there a way of finding out if a file is opened by someone - this file will be on a network drive. I looked on the FileSystemObject but could not see anything obvious to tell me.
0
Comment
Question by:donhannam
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 12

Expert Comment

by:danishani
ID: 36577015
Check below thread out of Ron de Bruin, scroll down, and you find a nice solution:
http://www.rondebruin.nl/exist.htm

Or this thread:
http://www.vbaexpress.com/kb/getarticle.php?kb_id=468

Hope this helps,
Daniel
0
 
LVL 20

Accepted Solution

by:
GrahamMandeno earned 500 total points
ID: 36577107
Hi Don

Try this function:
Public Function FileIsLocked(strFileName As String) As Boolean
Dim hFile As Long
  On Error Resume Next
  hFile = FreeFile
  Open strFileName For Input Lock Read Write As #hFile
  Select Case Err.Number
    Case 0
      Close #hFile
      FileIsLocked = False
    Case 70
      FileIsLocked = True
    Case Else
      MsgBox "Error opening " & strFileName & vbCrLf & Err.Description, vbExclamation
      FileIsLocked = True
  End Select
  Err.Clear
End Function

Open in new window


It simply attempts to open the file for exclusive read access and checks the failure status.

Best regards,
Graham Mandeno [Access MVP 1996-2011]
0
 

Author Closing Comment

by:donhannam
ID: 36578372
Thanks Graham works perfectly

danishani: Think the links you had effectively do the same thing but prefered the one Graham provided.
0

Featured Post

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

622 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question