LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Compare Username at Workbook Open

You may want to consider using a helper workbook that checks the credentials of
the user and if that's ok, it would open the real workbook.

If you give that real workbook a nice password, you could include the password
in the code in the helper workbook (and protect that workbook's project).

I'd create the helper workbook with two sheets. One that has instructions to
the user and one that has the list of valid users. Then I'd hide that second
sheet. It won't stop the very interested, but it would stop most(???).

I based my validation on Chip's post:

Option Explicit
Private Sub Workbook_Open()

Dim UserName As String
Dim V As Variant
dim myPWD as string
dim wkbk as workbook

UserName = Environ("username")

myPWD = "hi"

On Error Resume Next
V = Application.Match(UserName,
thisworkbook.worksheets("UserNames").range("a:a"), 0)
On Error Goto 0

If IsError(V) = True Then
Msgbox "You're not authorized!"
Else
Set wkbk = Workbooks.Open(Filename:="C:\my documents\excel\book1.xls", _
Password:=myPWD)

wkbk.RunAutoMacros which:=xlAutoOpen
end if

ThisWorkbook.Close savechanges:=False

End Sub

The users would always have to open this helper workbook first. If they
disabled macros, they'd see your instruction page. If they weren't authorized,
they'd see the msgbox.

If they enabled macros and were authorized, the helper workbook would open the
real workbook and then the helper workbook would close itself.

Tim wrote:

I wish to create a small security trap whereby a user cannot access a
file unless his/her username is within a named range. I know Excel
security is basic, but thats the level I'm at.

So if the user is not named in a named range a dialog box appears "No
access" etc and the file closes. The username I will compare against
the username on the xl 2007 panel. If the username matches open the
file as normal


--

Dave Peterson
 
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
Grab Open Outlook Username from Excel jayklmno Excel Programming 3 March 4th 08 10:22 PM
How to get username during workbooks.open macro Chuck W[_2_] Excel Programming 5 August 24th 07 04:58 PM
Windows API to get network username of person with file open Paul Martin Excel Programming 7 December 2nd 05 04:31 PM
Windows API to get network username of person with file open Paul Martin Excel Programming 0 November 30th 05 05:23 AM
XMLHTTP.OPEN + PASSWORD + USERNAME venk Excel Programming 0 March 17th 05 10:27 PM


All times are GMT +1. The time now is 06:53 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"