PDA

View Full Version : if worksheet already open then dont open again



vipulhumein
05-17-2013, 11:31 PM
I have made two worksheet linked with each other...when i click button "open my sheet" other worksheet automatically open in invisible mode and again if i click button "open my sheet' then a msg appears "you have already open the spec file do u want to reopen again.yes or no"..i want that if my "spec file already open " then dont open again...and the msg does not appear again..

also find the picture of the said msg which i have attached.

please help me out of this problem as soon as possible

thanks in advance..

vipulhumein
05-24-2013, 12:50 PM
someone please help me out of this problem

nepotist
05-29-2013, 01:21 PM
Function FileLocked(strFileName As String) As Boolean
On Error Resume Next
'Dim objAccess As Object
' Set objAccess = CreateObject("Access.Application")
' If the file is already opened by another process,
' and the specified type of access is not allowed,
' the Open operation fails and an error occurs.
Open strFileName For Binary Access Read Write Lock Read Write As #1
Close #1
' If an error occurs, the document is currently open.
If Err.Number <> 0 Then
' Display the error number and description.
' MsgBox "Error #" & Str(Err.Number) & " - " & Err.Description
FileLocked = True
Err.Clear

End If
End Function


Where StrFileName is the path to the file. You can modify the code to check is the file is locked it means the file is open.