Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 26
Default VBA Code to Login to Excel

Hello -

I have found the following code from this group. It works, to the
point that a message box pops with my user ID. But I am not sure if
this is what I need or if it is how to modify it as a login
varification to prevent other users from opening or viewing an excel
sheet.

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


Sub GetUserNameTest()
MsgBox "I am " & fOSUserName
End Sub


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

So, if I am not me, then I get access denied message...that is what
I'm looking for...is this code a good start, if it is how would I
modify to close the sheet if I'm not who I say I am...if it is not the
best way, then any ideas on how to do this?

Thanks..

  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1,726
Default VBA Code to Login to Excel


Private Sub Workbook_Open()
If Environ("Username") < "Gimp"
ThisWorkbook.Close SaveChanges:=False
EndIf
End Sub

'This is workbook event code.
'To input this code, right click on the Excel icon on the worksheet
'(or next to the File menu if you maximise your workbooks),
'select View Code from the menu, and paste the code


--
---
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)



"Gimp" wrote in message
ups.com...
Hello -

I have found the following code from this group. It works, to the
point that a message box pops with my user ID. But I am not sure if
this is what I need or if it is how to modify it as a login
varification to prevent other users from opening or viewing an excel
sheet.

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


Sub GetUserNameTest()
MsgBox "I am " & fOSUserName
End Sub


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

So, if I am not me, then I get access denied message...that is what
I'm looking for...is this code a good start, if it is how would I
modify to close the sheet if I'm not who I say I am...if it is not the
best way, then any ideas on how to do this?

Thanks..



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
How to stop a Smart Tag Login Dailog box when excel opens R. S. Excel Discussion (Misc queries) 0 January 13th 07 03:10 PM
Excel and Windows Login ID problem... Tad Anglin Setting up and Configuration of Excel 2 January 11th 07 03:18 PM
How do I automatically insert the user (login name) in Excel? ABlazer Excel Discussion (Misc queries) 1 September 19th 05 02:48 AM
Q:Excel/ODBC/Login .... MSweetG222 Excel Discussion (Misc queries) 1 July 24th 05 06:37 PM
Excel Driver login failed [email protected] Excel Discussion (Misc queries) 1 January 19th 05 01:34 AM


All times are GMT +1. The time now is 11:40 PM.

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

About Us

"It's about Microsoft Excel"