Hi,
I tried searching for vba code and was not able to find any.
I'm new to this thread and have a quick question.
I have created a userform with user name and password text box.
When user opens the excel sheet, the login userform will pop up asking for windows authetication.
Here is the code:
Declare Function GetUserName Lib "advapi32.dll" Alias _
"GetUserNameA" (ByVal lpBuffer As String, _
nSize As Long) As Long
Public Function GetWindowsLoginUserID() As String
Dim rtn As Long
Dim sBuffer As String
Dim lSize As Long
sBuffer = String$(260, Chr$(0))
lSize = Len(sBuffer)
rtn = GetUserName(sBuffer, lSize)
If rtn Then
sBuffer = Left$(sBuffer, lSize)
'Reformat string
If InStr(sBuffer, Chr$(0)) Then
sBuffer = Left$(sBuffer, InStr(sBuffer, Chr$(0)) - 1)
End If
GetWindowsLoginUserID = sBuffer
Else
'Error!
GetWindowsLoginUserID = ""
End If
End Function
Private Sub UserForm_Initialize()
UserName.Text = GetWindowsLoginUserID
End Sub
Now, how can i authenticate the password once the OK button is clicked on the userform. What dll i need to use to verify password.
TIA
SFL
I tried searching for vba code and was not able to find any.
I'm new to this thread and have a quick question.
I have created a userform with user name and password text box.
When user opens the excel sheet, the login userform will pop up asking for windows authetication.
Here is the code:
Declare Function GetUserName Lib "advapi32.dll" Alias _
"GetUserNameA" (ByVal lpBuffer As String, _
nSize As Long) As Long
Public Function GetWindowsLoginUserID() As String
Dim rtn As Long
Dim sBuffer As String
Dim lSize As Long
sBuffer = String$(260, Chr$(0))
lSize = Len(sBuffer)
rtn = GetUserName(sBuffer, lSize)
If rtn Then
sBuffer = Left$(sBuffer, lSize)
'Reformat string
If InStr(sBuffer, Chr$(0)) Then
sBuffer = Left$(sBuffer, InStr(sBuffer, Chr$(0)) - 1)
End If
GetWindowsLoginUserID = sBuffer
Else
'Error!
GetWindowsLoginUserID = ""
End If
End Function
Private Sub UserForm_Initialize()
UserName.Text = GetWindowsLoginUserID
End Sub
Now, how can i authenticate the password once the OK button is clicked on the userform. What dll i need to use to verify password.
TIA
SFL