Hi All,
I want to hide some buttons in Excel if a user doesn't belong to an AD group.
I can't get this code to work. It gives me an automation error, network path not found. GetcurrentUser and GetcurrentDomain work fine but the line: Set grp = GetObject(strPath & strGroup & ",group") gives me the error. Am I forgetting a reference or something?
Thanks in advance
I want to hide some buttons in Excel if a user doesn't belong to an AD group.
I can't get this code to work. It gives me an automation error, network path not found. GetcurrentUser and GetcurrentDomain work fine but the line: Set grp = GetObject(strPath & strGroup & ",group") gives me the error. Am I forgetting a reference or something?
Thanks in advance
Code:
If IsMember(GetCurrentDomain, "Everyone", GetCurrentUser) Then
'Do stuf
End If
Function IsMember(strDomain As String, strGroup As String, strMember As String) As Boolean
Dim grp As Object
Dim strPath As String
strPath = "WinNT://" & strDomain & "/"
Set grp = GetObject(strPath & strGroup & ",group")
IsMember = grp.IsMember(strPath & strMember)
End Function
Function GetCurrentUser() As String
GetCurrentUser = Environ("USERNAME")
End Function
Function GetCurrentDomain() As String
GetCurrentDomain = Environ("USERDOMAIN")
End Function