Hi all! Please help!
Well, the problem is straighforward. Hope you can help. Found nothing really working with google.
Many thanks in advance!
Hi all! Please help!
Well, the problem is straighforward. Hope you can help. Found nothing really working with google.
Many thanks in advance!
Hi, Alexander_Golinsky,
adapt the path and the name to suit:
![]()
Sub TestFileOpen() Dim iOpen As Integer Dim sFile As String Dim strPath As String strPath = "C:\Temp\" sFile = "your workbook.xlsm" If strPath & sFile = "" Then Exit Sub iOpen = TestOpen(strPath & sFile) Select Case iOpen Case 0: MsgBox "Workbook " & strPath & sFile & " is free" Case 1: MsgBox "The file is locked by " & GetFileOwner(strPath, sFile) & "." Case 2: MsgBox "Workbook " & strPath & sFile & " wasn´t found" End Select End Sub
![]()
Private Function TestOpen(sPath As String) As Integer If Dir(sPath) = "" Then TestOpen = 2 Else On Error GoTo ERRORHANDLER Open sPath For Random Access Read Lock Read Write As #1 Close #1 End If ERRORHANDLER: If Err = 70 Then TestOpen = 1 End Function
Ciao,![]()
Function GetFileOwner(fileDir As String, fileName As String) As String 'On Error Resume Next Dim secUtil As Object Dim secDesc As Object Set secUtil = CreateObject("ADsSecurityUtility") Set secDesc = secUtil.GetSecurityDescriptor(fileDir & fileName, 1, 1) GetFileOwner = secDesc.owner End Function
Holger
Use Code-Tags for showing your code: [code] Your Code here [/code]
Please mark your question Solved if there has been offered a solution that works fine for you
HaHobe, Thanks!
is what i looked for. I supose technically it's still opening but it's fast enough form me! Great!![]()
Open "F:\ANALIS\FIXD_INC\PRODUCTS\FI_Daily\Bondnames_FID.xlsm" For Random Access Read Lock Read Write As #1
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks