Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Lock access to a worksheet depending on user name

Hi all,

I'd like to allow accessing an Excel worksheet only to some users. The
user should be recognized depending on his user name (typed during
Windows login), but other ways could be valid as well. Obviously macro
should be enabled, otherwise no access though the user is enabled.

Can anyone give me any suggestion? Thanks in advance,

Steve.


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,885
Default Lock access to a worksheet depending on user name

Hi
just as an outline:
- create wor workbook with a visible sheet that says: Macros have to be
enabled. Hide all other sheets and protext the workbook
- Use the Workbook_open event to do the following (for event procedures
see: http://www.cpearson.com/excel/events.htm):
- check the username. E.g. use one of the functions from below:
- if the username is valid hide worksheet 1 (the one with the
macro notice) and unhide all other sheets
- If the username is not valid: issue a message and close the
workbook

So try something like the following:
'put the following in your workbook module:
Private Sub Workbook_Open()
dim uname
uname = XLUserName()

If lcase(uname)="myuser" then
'unhide worksheets and hide sheet 1
else
msgbox "your a re not allowed to open this workbook"
activeworkbook.close
end if

End Sub




'put the following procedures in a standard module:
-----
Public Function XLUserName() As String
XLUserName = Application.UserName
End Function

Public Function WinUserName() As String
WinUserName = Environ("UserName")
End Function



--
Regards
Frank Kabel
Frankfurt, Germany


Steve Aletto wrote:
Hi all,

I'd like to allow accessing an Excel worksheet only to some users.

The
user should be recognized depending on his user name (typed during
Windows login), but other ways could be valid as well. Obviously

macro
should be enabled, otherwise no access though the user is enabled.

Can anyone give me any suggestion? Thanks in advance,

Steve.


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Lock access to a worksheet depending on user name

From your reply:

'put the following procedures in a standard module:
-----
Public Function XLUserName() As String
XLUserName = Application.UserName
End Function

Public Function WinUserName() As String
WinUserName = Environ("UserName")
End Function


---
I have tried this and find out that the second function is not used
And the username is not the login name of the window.

And when I replace the XLUserName = Application.UserName to
XLUserName = WinUserName , I got a compile error:

"Can't find project or Library"

Anything I did wrong here, Please help. Thanks in advanc

--
Message posted from http://www.ExcelForum.com

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,824
Default Lock access to a worksheet depending on user name

Put these in a general module. They work together to get the logon name.



Private Declare Function apiGetUserName Lib "advapi32.dll" Alias _
"GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long

Function fOSUserName() As String
' Returns the network login name
Dim lngLen As Long, lngX As Long
Dim strUserName As String
strUserName = String$(254, 0)
lngLen = 255
lngX = apiGetUserName(strUserName, lngLen)
If lngX < 0 Then
fOSUserName = Left$(strUserName, lngLen - 1)
Else
fOSUserName = ""
End If
End Function



"dragontale <" wrote:

From your reply:

'put the following procedures in a standard module:
-----
Public Function XLUserName() As String
XLUserName = Application.UserName
End Function

Public Function WinUserName() As String
WinUserName = Environ("UserName")
End Function

---
I have tried this and find out that the second function is not used.
And the username is not the login name of the window.

And when I replace the XLUserName = Application.UserName to
XLUserName = WinUserName , I got a compile error:

"Can't find project or Library"

Anything I did wrong here, Please help. Thanks in advance

---
Message posted from http://www.ExcelForum.com/


--

Dave Peterson

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Lock access to a worksheet depending on user name


"Frank Kabel" ha scritto nel messaggio
...
Hi
just as an outline:


Many thanks.

Steve.




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Lock access to a worksheet depending on user name

Thanks a lot and it is working

--
Message posted from http://www.ExcelForum.com

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
activate/deactivate macro depending on who's the user anna Excel Discussion (Misc queries) 3 January 24th 10 11:11 PM
Defining user access (via user id) using macros maruko Excel Discussion (Misc queries) 0 July 27th 09 02:44 AM
Excel crashes depending on user?? Khuli Excel Discussion (Misc queries) 0 June 17th 09 11:04 AM
Lock and unlock cells conditionally depending on input in another Frustrated Excel Worksheet Functions 1 November 11th 05 03:36 PM
Multi-User Access to a worksheet Brad[_7_] Excel Programming 1 August 27th 03 02:30 AM


All times are GMT +1. The time now is 09:35 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"