View Full Version : how to check if file is read only, but from other file
danovkos
11-12-2009, 06:27 AM
hi all,
how can i check follow:
I have opened file A
And after run code i want to check if is file B opened read only?
i tried this, but doesnt works: :(
set target = Workbooks.Open FileName:= "Y:\path\aa\bb\B", UpdateLinks:=0
If target.ReadOnly = True Then MsgBox "read-only"
maybe i need define instead thisworkbook to path to file B?
thx a lot
Bob Phillips
11-12-2009, 06:56 AM
This should work
set target = Workbooks.Open(FileName:= "Y:\path\aa\bb\B", UpdateLinks:=0)
If target.ReadOnly = True Then MsgBox "read-only"
danovkos
11-12-2009, 07:03 AM
this open a file B and check it
but is it possible without opening the file B?
maybe not or?
thx
Bob Phillips
11-12-2009, 07:23 AM
Not as stated as Readonly only appies to workbooks open.
You can check if the file is alraedy in use with
Function IsFileOpen(FileName As String)
Dim iFilenum As Long
Dim iErr As Long
On Error Resume Next
iFilenum = FreeFile()
Open FileName For Input Lock Read As #iFilenum
Close iFilenum
iErr = Err
On Error GoTo 0
Select Case iErr
Case 0: IsFileOpen = False
Case 70: IsFileOpen = True
Case Else: Error iErr
End Select
End Function
Sub test()
If Not IsFileOpen("C:\MyTest\volker2.xls") Then
Workbooks.Open "C:\MyTest\volker2.xls"
End If
End Sub
danovkos
11-12-2009, 07:35 AM
OK it works, thank you...and is possible to figured out, who opened this file. I mean username of person whos open this file?
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.