ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Read folder access rights (https://www.excelbanter.com/excel-programming/344007-read-folder-access-rights.html)

Eric van Uden[_2_]

Read folder access rights
 
Hello group,

This has probably been answered before, bu I cannot locate the answer.
Before opening a workbook from another workbook, I need to check if the user
has write permission for the file.
Then I can warn the user if opening the file to continue the procedure
would be useless, and offer a cancel.

Using Excel 2k and up on WinXP boxes, WinNT and Server 2k3 networking.

Any pointers would be appreciated.

Eric



Bob Phillips[_6_]

Read folder access rights
 
Eric,

You could just open the file and check if it is open read-only

Dim sFile As String

sFile = "C:\myTest\volker1.xls"
On Error GoTo file_error
Workbooks.Open Filename:=sFile
If ActiveWorkbook.ReadOnly = True Then
MsgBox sFile & " is in read-only", 5, "Title", vbYesNo
ActiveWorkbook.Close savechanges:=False
Exit Sub
End If

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Eric van Uden" <eric[ @ ]doornroosje[ . ]nl wrote in message
...
Hello group,

This has probably been answered before, bu I cannot locate the answer.
Before opening a workbook from another workbook, I need to check if the

user
has write permission for the file.
Then I can warn the user if opening the file to continue the procedure
would be useless, and offer a cancel.

Using Excel 2k and up on WinXP boxes, WinNT and Server 2k3 networking.

Any pointers would be appreciated.

Eric





Eric van Uden[_2_]

Read folder access rights
 
Thanks Bob,

Your answer confirms what I have gathered from miscellaneous remarks all
over the web, that there is probably to way to 'test the water' other than
by jumping in. Still, I am surprised that with all the shell and filsesystem
objects and properties, and all the networking, there's no direct way of
knowing whether the current user has rights in a folder. Maybe I should look
into WMI rather than native Excel objects...

For now, and for my immediate purpose, though, your solution is probably the
way to go.

Thanks for the acurate sample code.

Eric


"Bob Phillips" schreef in bericht
...
Eric,

You could just open the file and check if it is open read-only

Dim sFile As String

sFile = "C:\myTest\volker1.xls"
On Error GoTo file_error
Workbooks.Open Filename:=sFile
If ActiveWorkbook.ReadOnly = True Then
MsgBox sFile & " is in read-only", 5, "Title", vbYesNo
ActiveWorkbook.Close savechanges:=False
Exit Sub
End If

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Eric van Uden" <eric[ @ ]doornroosje[ . ]nl wrote in message
...
Hello group,

This has probably been answered before, bu I cannot locate the answer.
Before opening a workbook from another workbook, I need to check if the

user
has write permission for the file.
Then I can warn the user if opening the file to continue the procedure
would be useless, and offer a cancel.

Using Excel 2k and up on WinXP boxes, WinNT and Server 2k3 networking.

Any pointers would be appreciated.

Eric







Bob Phillips[_6_]

Read folder access rights
 
Eric,

There probably is a way using APIs and stuff, I just gave you the way I use
it. I will take a little look, and if I work something out I will post it
back to you. Access rights get a bit hairy though.

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Eric van Uden" <ericvanuden wanadoo nl wrote in message
...
Thanks Bob,

Your answer confirms what I have gathered from miscellaneous remarks all
over the web, that there is probably to way to 'test the water' other than
by jumping in. Still, I am surprised that with all the shell and

filsesystem
objects and properties, and all the networking, there's no direct way of
knowing whether the current user has rights in a folder. Maybe I should

look
into WMI rather than native Excel objects...

For now, and for my immediate purpose, though, your solution is probably

the
way to go.

Thanks for the acurate sample code.

Eric


"Bob Phillips" schreef in bericht
...
Eric,

You could just open the file and check if it is open read-only

Dim sFile As String

sFile = "C:\myTest\volker1.xls"
On Error GoTo file_error
Workbooks.Open Filename:=sFile
If ActiveWorkbook.ReadOnly = True Then
MsgBox sFile & " is in read-only", 5, "Title", vbYesNo
ActiveWorkbook.Close savechanges:=False
Exit Sub
End If

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Eric van Uden" <eric[ @ ]doornroosje[ . ]nl wrote in message
...
Hello group,

This has probably been answered before, bu I cannot locate the answer.
Before opening a workbook from another workbook, I need to check if the

user
has write permission for the file.
Then I can warn the user if opening the file to continue the procedure
would be useless, and offer a cancel.

Using Excel 2k and up on WinXP boxes, WinNT and Server 2k3 networking.

Any pointers would be appreciated.

Eric









Dennis

Read folder access rights
 
First, I want to thank Bob and Eric for their help!
(Eric also posted my question)

Secondly, I want to apologize, because I had a brainwave during the
washing-up which led to an answer to my own question...

Try to create something in the folder in question, e.g. a new folder.
Here's my code:

Function Right_to_Write_in_Folder(FolderFullName As String) As Boolean
'(Dennis Tharmaratnam)
Dim FSO As Object, Dummy As Object

Set FSO = CreateObject("Scripting.FileSystemObject")
If Right(FolderFullName, 1) < "\" Then FolderFullName = FolderFullName &
"\"
On Error GoTo No_Right
Set Dummy = FSO.CreateFolder(FolderFullName & "Dummy" & Format(Rnd *
1000000000, "0"))
Right_to_Write_in_Folder = True
Dummy.Delete
Set Dummy = Nothing
No_Right:
Set FSO = Nothing
End Function

(Assumptions: folder FolderFullName exists and the user has the right to
read it's contents)

I hope the answer is useful to others too.


Kind regards,

Dennis Tharmaratnam


"Bob Phillips" schreef in bericht
...
Eric,

There probably is a way using APIs and stuff, I just gave you the way I
use
it. I will take a little look, and if I work something out I will post it
back to you. Access rights get a bit hairy though.

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Eric van Uden" <ericvanuden wanadoo nl wrote in message
...
Thanks Bob,

Your answer confirms what I have gathered from miscellaneous remarks all
over the web, that there is probably to way to 'test the water' other
than
by jumping in. Still, I am surprised that with all the shell and

filsesystem
objects and properties, and all the networking, there's no direct way of
knowing whether the current user has rights in a folder. Maybe I should

look
into WMI rather than native Excel objects...

For now, and for my immediate purpose, though, your solution is probably

the
way to go.

Thanks for the acurate sample code.

Eric


"Bob Phillips" schreef in bericht
...
Eric,

You could just open the file and check if it is open read-only

Dim sFile As String

sFile = "C:\myTest\volker1.xls"
On Error GoTo file_error
Workbooks.Open Filename:=sFile
If ActiveWorkbook.ReadOnly = True Then
MsgBox sFile & " is in read-only", 5, "Title", vbYesNo
ActiveWorkbook.Close savechanges:=False
Exit Sub
End If

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Eric van Uden" <eric[ @ ]doornroosje[ . ]nl wrote in message
...
Hello group,

This has probably been answered before, bu I cannot locate the answer.
Before opening a workbook from another workbook, I need to check if
the
user
has write permission for the file.
Then I can warn the user if opening the file to continue the
procedure
would be useless, and offer a cancel.

Using Excel 2k and up on WinXP boxes, WinNT and Server 2k3 networking.

Any pointers would be appreciated.

Eric












All times are GMT +1. The time now is 10:36 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com