473,399 Members | 2,774 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

how to check if an excel file stored on a network drive is in use?

7
I have an excel file that I need to check if its in use by another before i open it.
I have found various forms of the follwing code but each one give me the same errors at the following 2 lines when I compile it using vb.net 2005 express
(1)
Open strFileSpec For Input Lock Read As intFn
'error = open not declared, missing comma etc.
(2)
Close(intFn)
'error = to many arguments to public Sub Close()
I'd really appreciate any ideas!




Function IsFileOpen(ByVal strFileSpec As String) As Boolean
' Purpose Test to see if the file has been locked by another process
Dim intFn As Integer, lngErrNum As Long, strErrDescr As String

On Error Resume Next ' No Error checking
intFn = FreeFile() ' Get a free file number.
' Attempt to open the file and lock it.
Open strFileSpec For Input Lock Read As intFn
Close(intFn) ' Close the file.
lngErrNum = Err.Number ' Save the error number that occurred.
strErrDescr = Err.Description
On Error GoTo 0 ' Turn error checking back on.
' Report the error
Select Case lngErrNum
Case 0
' No error occurred - File is NOT already open by another user.
IsFileOpen = False
Case 70
' Error number for "Permission Denied. - File is opened by another user.
IsFileOpen = True
Case Else
' Yikes some other error occurred.
IsFileOpen = False
MsgBox("Error! " & vbCrLf & "Error Number " & lngErrNum & vbCrLf & "Error Descr " & strErrDescr, vbExclamation, "IsFileOpen()")
End Select
End Function
Oct 16 '07 #1
0 1895

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: allyn44 | last post by:
Hi, I have a small databse that outputs 2 excel files to a folder. DoCmd.TransferSpreadsheet acExport, , "randtrack",_ "C:\randomization\Trackrandomization.xls" The person wants to put the...
7
by: Ajit | last post by:
Is there anyway to check for existance of a file on different machine. i.e. we have a data file (text file) thats stored on some other machine as its not to be exposed in case the web server is...
3
by: Rich Ulichny | last post by:
Not sure if this is correct newsgroup but I figured I had to start somewhere. We need to build a Web based application to allow users to choose an Excel file from their hard drive (or other...
6
by: Daniel | last post by:
Hi all, Can i open and edit the excel sheet on web page after downloading? After editing, i close the web page and the excel file auto upload to the server. Is it possible? I really struggling...
2
by: Peter S. | last post by:
I have an ASP.NET page that invokes a web control written in C#. What I want to do is (based on the session ID) display a certain spreadsheet that exists on a network drive. I want the webcontrol...
5
by: =?Utf-8?B?U3R1YXJ0?= | last post by:
Hi There I have been having a play around with the following code to display a datagrid in Excel (all from Steve Orr's site): Private Sub btnTechServAccred_Click(ByVal sender As System.Object,...
9
by: Doug Glancy | last post by:
I got the following code from Francesco Balena's site, for disposing of Com objects: Sub SetNothing(Of T)(ByRef obj As T) ' Dispose of the object if possible If obj IsNot Nothing AndAlso...
0
Boxcar74
by: Boxcar74 | last post by:
Hi Everybody!!! I have an Issue. I have an Excel file that queries an Access db. I’m trying to have it so I don’t have to keep updating it manually everyday and save it to a network drive...
0
by: hidara | last post by:
Hello there. I'm trying to write a program that will insert data into an excel sheet every time it is excecuted. This file is stored on a network drive. How can VB.net check if the file is open by...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.